Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making user work #250

Closed
wants to merge 31 commits into from
Closed

Making user work #250

wants to merge 31 commits into from

Conversation

kjain110
Copy link
Contributor

No description provided.

@kjain110 kjain110 changed the base branch from master to poc April 25, 2024 17:37
@kjain110 kjain110 changed the base branch from poc to proof-of-concept April 25, 2024 17:38
@kjain110 kjain110 changed the base branch from proof-of-concept to poc April 25, 2024 17:45
return Optional.of(entityType);
}

private void buildCompositeEntityTypeDefinition(EntityType entityType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code above is commented out, this method is unused

return Optional.of(entityType);
}

private void buildCompositeEntityTypeDefinition(EntityType entityType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method's name isn't very clear to me. When I see build_____(), I'd normally expect the method to return something. When I see that name but it's void, I have to go read the code to understand what it does

return Optional.of(entityType);
}

private void buildCompositeEntityTypeDefinition(EntityType entityType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong, but at a quick glance, it looks like this method can/should be static

}

private void buildCompositeEntityTypeDefinition(EntityType entityType) {
System.out.println("BUILD COMPOSITE DEFINITION");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These System.out.println() calls should be replaced with calls to the logger

System.out.println("BUILD COMPOSITE DEFINITION");
List<EntityTypeSourceJoin> entityTypeSourceJoins = new ArrayList<>();
List<EntityTypeSource> sources = entityType.getSources();
entityType.setFromClause("BUILD COMPOSITE DEFINITION");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion: we should avoid using the fromClause if we're not actually using it for real, so that we can remove it from the object model ASAP. The more we use it, the harder it will be to remove

Comment on lines +181 to +183
EntityTypeSourceJoin join = source.getJoin();
String joinType = join.getType();
String joinCondition = join.getCondition();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stating the obvious here since this is implied by the comment above, but if source.getJoin() is null, we'll get an NPE here (and NPEs are always bugs)

if (i == 0) { // TODO: think about replacing this with -- if (source.getJoin() == null)
fromClause.append(source.getAlias());
} else {
if (source.getType().equals("db")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (source.getType().equals("db")) {
if ("db".equals(source.getType())) {

This way, we handles nulls and avoid a potential NPE

@@ -63,12 +69,12 @@ public int streamIdsInBatch(UUID queryId,
Consumer<IdsWithCancelCallback> idsConsumer) {
UUID entityTypeId = queryDetailsRepository.getEntityTypeId(queryId);
EntityType entityType = getEntityType(entityTypeId);
Condition condition = field(ID_FIELD_NAME).in(
Condition condition = field("\"source1\".id").in(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to do something with this string before we merge this :)

Comment on lines +106 to +111
String finalWhereClause = sqlWhereClause.toString();
for (EntityTypeSource source : entityType.getSources()) {
String toReplace = ":" + source.getAlias();
String alias = "\"" + source.getAlias() + "\"";
finalWhereClause = finalWhereClause.replace(toReplace, alias);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this replacement by using SQL parameters, if at all possible. Doing it manually is generally pretty dangerous and bug-prone. The code for handling valueFunction does it that way, so it could be a useful reference

@@ -104,11 +109,28 @@ public List<Map<String, Object>> getResultSet(UUID entityTypeId, Fql fql, List<S
}

Condition condition = FqlToSqlConverterService.getSqlCondition(fql.fqlCondition(), entityType);
// TODO: might want to put next 5 lines in its own method in EntityTypeFlatteningService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree 100%, especially since this same code shows up in IdStreamer

.stream()
.filter(EntityTypeColumn::getIsIdColumn)
.findFirst()
.orElseThrow()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw a specific exception, or at least a generic one with a clear error message

.name(originalEntityType.getName())
._private(originalEntityType.getPrivate())
.defaultSort(originalEntityType.getDefaultSort())
.columns(originalEntityType.getColumns()) // TODO: probably remove
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion: don't remove it. If we keep the columns, it makes it possible to augment an existing entity type by importing it and adding some fields

Pair<EntityTypeSource, List<EntityTypeColumn>> updatePair = getConvertedSourceAndColumns(originalEntityType, source, null, false); // TODO: think about this, may not be able to hardcode false here
flattenedEntityType.addSourcesItem(updatePair.component1());
finalColumns.addAll(updatePair.component2());
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably check for "entity-type" here and throw an exception when it's not one of the valid values.

package org.folio.fqm.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import kotlin.Pair;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use a different implementation of Pair. We're not actually using Kotlin (unfortunately), so it just feels weird to use stuff from its standard lib

List<EntityTypeColumn> finalColumns = new ArrayList<>();
for (EntityTypeSource source : originalEntityType.getSources()) {
if (source.getType().equals("db")) {
Pair<EntityTypeSource, List<EntityTypeColumn>> updatePair = getConvertedSourceAndColumns(originalEntityType, source, null, false); // TODO: think about this, may not be able to hardcode false here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments like this make me wish we were using something where you can name parameters at the call-site, like kotlin. I have no idea what the false does here, which is something that could be fixed at the language-level if Java supported it ☹️

Comment on lines +60 to +63
// If an entity type source contains multiple db sources, then we need to keep the original alias in order to
// distinguish the different targets. Frequently, it will likely only have one db source. In this case we
// can use the outer alias only, in order to keep field names more concise
boolean keepOriginalAlias = countDbSources(flattenedSourceDefinition) > 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion, but I could probably be swayed pretty easily: don't bother with this. I'd prefer less concise field names if it means simpler code and more consistent behavior.

return Optional.of(flattenedEntityType);
}

public String getJoinClause(EntityType flattenedEntityType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't like this name, since afaik, there's no such thing as a join clause

return orderedList;
}

private static void dfs(EntityTypeSource source, Map<String, EntityTypeSource> sourceMap, Set<String> visited, List<EntityTypeSource> orderedList) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this method name, personally. I had to actually read the code to understand the name

orderedList.add(source);
}

private void updateOtherSources(String oldSourceName, String newSourceName, List<EntityTypeSource> otherSources) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name is killing me, too 😛 I dunno what "other sources" are, so it might as well be named doThings() 🙂

return entityType
.getSources()
.stream()
.filter(source -> !Boolean.TRUE.equals(source.getFlattened()) && source.getType().equals("db"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set the type to "flattened" or something and get rid of the flattened property? That'd simplify the object model a bit and probably simplify some code outside this method, too, too

}
}

private long countDbSources(EntityType entityType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private long countDbSources(EntityType entityType) {
private static long countDbSources(EntityType entityType) {

@kjain110 kjain110 closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants