Skip to content

handle array columns in Trino handler #201

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

Merged
merged 14 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions query-service-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
implementation("org.apache.helix:helix-core:1.3.0") {
because("CVE-2022-47500")
}
implementation("org.apache.zookeeper:zookeeper:3.7.2") {
because("CVE-2023-44981")
}
implementation("org.webjars:swagger-ui:5.1.0") {
because("CVE-2019-16728,CVE-2020-26870")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,37 +243,60 @@ private void handleConversionForArrayColumnExpression(

if (handleConversionForNullOrEmptyArrayLiteral(lhs, operator, builder, value)) return;

// support only equals and IN operator
// both of them are handled as contains check to align with existing implementation
if (operator.equals("=")
|| operator.equals("IN")
|| operator.equals("!=")
|| operator.equals("NOT IN")) {
// add NOT operator to negate the match condition
if (operator.equals("!=") || operator.equals("NOT IN")) {
// Support only equals and IN operator
if (operator.equals("=") || operator.equals("!=")) {
// Equals (=): CONTAINS(ip_types, 'Bot')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: changes looks fine. For readability, would it make sense to move to a function?

// Not equals (!=): NOT CONTAINS(ip_types, 'Bot')
if (operator.equals("!=")) {
builder.append("NOT ");
}
builder.append("CONTAINS(");
builder.append(lhs);
// overlap operator for array
builder.append(" && ");
builder.append(", ");
if (value.getValueType() == ValueType.STRING) {
builder.append(QUESTION_MARK);
paramsBuilder.addStringParam(value.getString());
} else {
throw new IllegalArgumentException(
String.format("Unsupported value {%s} for array column", value));
}
builder.append(")");
} else if (operator.equals("IN") || operator.equals("NOT IN")) {
// IN: CARDINALITY(ARRAY_INTERSECT(ip_types, ARRAY['Public Proxy', 'Bot'])) > 0
// NOT IN: CARDINALITY(ARRAY_INTERSECT(ip_types, ARRAY['Public Proxy', 'Bot'])) = 0
builder.append("CARDINALITY(");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: changes looks fine. For readability, would it make sense to move to a function?

builder.append("ARRAY_INTERSECT(");
builder.append(lhs);
builder.append(", ARRAY[");
switch (value.getValueType()) {
case STRING:
builder.append(QUESTION_MARK);
paramsBuilder.addStringParam(value.getString());
break;
case STRING_ARRAY:
String delim = "";
for (String item : value.getStringArrayList()) {
builder.append(delim);
builder.append(QUESTION_MARK);
paramsBuilder.addStringParam(item);
delim = ", ";
}
break;
default:
throw new IllegalArgumentException(
String.format("Unsupported value {%s} for array column", value));
}
builder.append("]))");
if (operator.equals("IN")) {
builder.append(" > 0");
} else {
builder.append(" = 0");
}
} else {
throw new IllegalArgumentException(
String.format(
"Unsupported operator {%s} for array column with non-empty value", operator));
}
builder.append("?");
switch (value.getValueType()) {
case STRING:
paramsBuilder.addStringParam("{" + value.getString() + "}");
break;
case STRING_ARRAY:
paramsBuilder.addStringParam("{" + String.join(", ", value.getStringArrayList()) + "}");
break;
default:
throw new IllegalArgumentException(
String.format("Unsupported value {%s} for array column", value));
}
builder.append(QUESTION_MARK);
}

private boolean handleConversionForNullOrEmptyArrayLiteral(
Expand Down
Loading