in data-catalog-api/server/service/src/main/java/org/apache/airavata/datacatalog/api/query/impl/PostgresqlMetadataSchemaQueryWriterImpl.java [102:157]
public SqlNode visit(SqlCall call) {
SqlCall currentOperator = this.binaryLogicalOperatorNodes.peek();
while (currentOperator != null
&& !call.getParserPosition().overlaps(currentOperator.getParserPosition())) {
this.binaryLogicalOperatorNodes.remove();
currentOperator = this.binaryLogicalOperatorNodes.peek();
this.sql.append(" ) ");
this.sql.append(currentOperator.getOperator().toString());
this.sql.append(" ");
}
if (call.getKind() == SqlKind.NOT) {
this.sql.append(" NOT ");
} else if (call.getKind() == SqlKind.AND || call.getKind() == SqlKind.OR) {
this.binaryLogicalOperatorNodes.push(call);
this.sql.append("( ");
} else {
SqlNode sqlNode = call.getOperandList().get(0);
// TODO: this assumes that there would only ever be one metadata schema field
// and that it comes first and the second operand is a literal
if (sqlNode.isA(Set.of(SqlKind.IDENTIFIER))) {
SqlIdentifier sqlIdentifier = (SqlIdentifier) sqlNode;
MetadataSchemaFieldEntity metadataSchemaField = resolveMetadataSchemaField(sqlIdentifier);
if (metadataSchemaField != null) {
// TODO: assuming an alias
sql.append(sqlIdentifier.names.get(0));
sql.append(".");
sql.append("metadata @@ '");
sql.append(metadataSchemaField.getJsonPath());
sql.append(" ");
switch (call.getOperator().kind) {
case EQUALS:
sql.append(" == ");
break;
default:
sql.append(call.getOperator().kind.sql);
break;
}
sql.append(call.getOperandList().get(1).toSqlString(new PostgresqlSqlDialect(
PostgresqlSqlDialect.DEFAULT_CONTEXT.withLiteralQuoteString("\""))));
sql.append("'");
} else {
sql.append(call.toSqlString(PostgresqlSqlDialect.DEFAULT));
}
}
if (currentOperator != null && !(call.getParserPosition().getEndColumnNum() == currentOperator
.getParserPosition().getEndColumnNum()
&& call.getParserPosition().getEndLineNum() == currentOperator.getParserPosition()
.getEndLineNum())) {
sql.append(" ");
sql.append(currentOperator.getOperator().toString());
sql.append(" ");
}
}
return super.visit(call);
}