Skip to content

Commit

Permalink
avniproject#762 | Shiftedcondition node to MetabaseJoin
Browse files Browse the repository at this point in the history
  • Loading branch information
ombhardwajj committed Aug 25, 2024
1 parent 812b4bd commit a780ef6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ public class MetabaseJoin {
private final int sourceTable;
private final JsonNode condition;

public MetabaseJoin(String fields, String alias, int sourceTable, JsonNode condition) {
// Constructor with conditionNode logic
public MetabaseJoin(String fields, String alias, int sourceTable, int joinFieldId1, int joinFieldId2, String tableName, ObjectMapper objectMapper) throws Exception {
this.fields = fields;
this.alias = alias;
this.sourceTable = sourceTable;
this.condition = condition;

// Creating the conditionNode within the constructor
this.condition = createConditionNode(joinFieldId1, joinFieldId2, tableName, objectMapper);
}

// Method to create the conditionNode
private JsonNode createConditionNode(int joinFieldId1, int joinFieldId2, String tableName, ObjectMapper objectMapper) throws Exception {
return objectMapper.readTree(
"[\"=\", [\"field\", " + joinFieldId1 + ", {\"base-type\": \"type/Integer\"}], [\"field\", " + joinFieldId2 + ", {\"base-type\": \"type/Integer\", \"join-alias\": \"" + tableName + "\"}]]"
);
}

// Method to convert to JSON
public ObjectNode toJson(ObjectMapper objectMapper) {
ObjectNode joinNode = objectMapper.createObjectNode();
joinNode.put("fields", this.fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ private void createQuestionForTable(String tableName, String addressTableName, S
int tableId = getTableIdByName(tableName);
int joinFieldId2 = getFieldIdByTableNameAndFieldName(tableName, tableField);

JsonNode conditionNode = objectMapper.readTree(
"[\"=\", [\"field\", " + joinFieldId1 + ", {\"base-type\": \"type/Integer\"}], [\"field\", " + joinFieldId2 + ", {\"base-type\": \"type/Integer\", \"join-alias\": \"" + tableName + "\"}]]"
);
MetabaseJoin join = new MetabaseJoin("all", tableName, tableId, conditionNode);
MetabaseJoin join = new MetabaseJoin("all", tableName, tableId, joinFieldId1, joinFieldId2, tableName, objectMapper);

ArrayNode joinsArray = objectMapper.createArrayNode();
joinsArray.add(join.toJson(objectMapper));
Expand Down

0 comments on commit a780ef6

Please sign in to comment.