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

IGNITE-23676 SQL Calcite: Fix sensitive information removal failure f… #11663

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.util.SqlOperatorTables;
import org.apache.calcite.sql.util.SqlShuttle;
import org.apache.calcite.sql.validate.SqlValidator;
Expand Down Expand Up @@ -550,7 +551,15 @@ private String removeSensitive(SqlNode qry) {
return qry.accept(
new SqlShuttle() {
@Override public SqlNode visit(SqlLiteral literal) {
return new SqlDynamicParam(-1, literal.getParserPosition());
// Process only certain data types, where it's justified to hide information.
// Don't touch enums and boolean literals, since they can be used as internal field values
// for some SQL nodes.
if (SqlTypeName.STRING_TYPES.contains(literal.getTypeName())
|| SqlTypeName.NUMERIC_TYPES.contains(literal.getTypeName())
|| SqlTypeName.DATETIME_TYPES.contains(literal.getTypeName()))
return new SqlDynamicParam(-1, literal.getParserPosition());

return literal;
}

@Override public SqlNode visit(SqlCall call) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ public void testSensitiveInformationHiding() throws Exception {
sql(grid(0), "CREATE USER test WITH PASSWORD 'sensitive'");
sql(grid(0), "ALTER USER test WITH PASSWORD 'sensitive'");

// Test JOIN.
sql(grid(0),
"SELECT * FROM test_sens t1 JOIN test_sens t2 ON t1.id = t2.id WHERE t1.val like 'sensitive%'");

AtomicInteger qryCnt = new AtomicInteger();
AtomicInteger planCnt = new AtomicInteger();

Expand Down Expand Up @@ -708,8 +712,8 @@ public void testSensitiveInformationHiding() throws Exception {
}
});

assertEquals(12, qryCnt.get()); // CREATE AS SELECT counts as two queries.
assertEquals(7, planCnt.get()); // DDL queries don't produce plans, except CREATE AS SELECT.
assertEquals(13, qryCnt.get()); // CREATE AS SELECT counts as two queries.
assertEquals(8, planCnt.get()); // DDL queries don't produce plans, except CREATE AS SELECT.
}
finally {
QueryUtils.INCLUDE_SENSITIVE = true;
Expand Down