Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public Procedure getProcedure()
"runtime",
"kill_query",
ImmutableList.<Argument>builder()
.add(new Argument("query_id", VARCHAR))
.add(new Argument("message", VARCHAR))
.add(new Argument("QUERY_ID", VARCHAR))
.add(new Argument("MESSAGE", VARCHAR))
.build(),
KILL_QUERY.bindTo(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ListenableFuture<Void> execute(
for (int i = 0; i < call.getArguments().size(); i++) {
CallArgument argument = call.getArguments().get(i);
if (argument.getName().isPresent()) {
String name = argument.getName().get();
String name = argument.getName().get().getCanonicalValue();
if (names.put(name, argument) != null) {
throw semanticException(INVALID_ARGUMENTS, argument, "Duplicate procedure argument: %s", name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ private Map<String, Expression> processTableExecuteArguments(TableExecute node,
if (anyNamed) {
// all properties named
for (CallArgument argument : arguments) {
if (argumentsMap.put(argument.getName().get(), argument.getValue()) != null) {
if (argumentsMap.put(argument.getName().get().getCanonicalValue(), argument.getValue()) != null) {
throw semanticException(DUPLICATE_PROPERTY, argument, "Duplicate named argument: %s", argument.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@ public Node visitPositionalArgument(SqlBaseParser.PositionalArgumentContext cont
@Override
public Node visitNamedArgument(SqlBaseParser.NamedArgumentContext context)
{
return new CallArgument(getLocation(context), context.identifier().getText(), (Expression) visit(context.expression()));
return new CallArgument(getLocation(context), (Identifier) visit(context.identifier()), (Expression) visit(context.expression()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public final class CallArgument
extends Node
{
private final Optional<String> name;
private final Optional<Identifier> name;
private final Expression value;

public CallArgument(Expression value)
Expand All @@ -38,24 +38,24 @@ public CallArgument(NodeLocation location, Expression value)
this(Optional.of(location), Optional.empty(), value);
}

public CallArgument(String name, Expression value)
public CallArgument(Identifier name, Expression value)
{
this(Optional.empty(), Optional.of(name), value);
}

public CallArgument(NodeLocation location, String name, Expression value)
public CallArgument(NodeLocation location, Identifier name, Expression value)
{
this(Optional.of(location), Optional.of(name), value);
}

public CallArgument(Optional<NodeLocation> location, Optional<String> name, Expression value)
public CallArgument(Optional<NodeLocation> location, Optional<Identifier> name, Expression value)
{
super(location);
this.name = requireNonNull(name, "name is null");
this.value = requireNonNull(value, "value is null");
}

public Optional<String> getName()
public Optional<Identifier> getName()
{
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1909,8 +1909,8 @@ public void testTableExecute()
table,
procedure,
ImmutableList.of(
new CallArgument("bah", new LongLiteral("1")),
new CallArgument("wuh", new StringLiteral("clap"))),
new CallArgument(identifier("bah"), new LongLiteral("1")),
new CallArgument(identifier("wuh"), new StringLiteral("clap"))),
Optional.of(
new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN,
new Identifier("age"),
Expand Down Expand Up @@ -2577,8 +2577,8 @@ public void testCall()
assertStatement("CALL foo()", new Call(QualifiedName.of("foo"), ImmutableList.of()));
assertStatement("CALL foo(123, a => 1, b => 'go', 456)", new Call(QualifiedName.of("foo"), ImmutableList.of(
new CallArgument(new LongLiteral("123")),
new CallArgument("a", new LongLiteral("1")),
new CallArgument("b", new StringLiteral("go")),
new CallArgument(identifier("a"), new LongLiteral("1")),
new CallArgument(identifier("b"), new StringLiteral("go")),
new CallArgument(new LongLiteral("456")))));
}

Expand Down
14 changes: 14 additions & 0 deletions core/trino-spi/src/main/java/io/trino/spi/procedure/Procedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,22 @@ public Argument(String name, Type type)
}

public Argument(String name, Type type, boolean required, @Nullable Object defaultValue)
{
this(name, false, type, required, defaultValue);
}

/**
* @deprecated Available for transition period only. After the transition period non-uppercase names will always be allowed.
*/
@Deprecated
public Argument(String name, boolean allowNonUppercaseName, Type type, boolean required, @Nullable Object defaultValue)
{
this.name = checkNotNullOrEmpty(name, "name");
if (!allowNonUppercaseName && !name.equals(name.toUpperCase(ENGLISH))) {
throw new IllegalArgumentException("Argument name not uppercase. Previously argument names were matched incorrectly. " +
"This is now fixed and for backwards compatibility of CALL statements, the argument must be declared in uppercase. " +
"You can pass allowNonUppercaseName boolean flag if you want to register non-uppercase argument name.");
}
this.type = requireNonNull(type, "type is null");
this.required = required;
this.defaultValue = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@
import static io.trino.spi.block.MethodHandleUtil.methodHandle;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class FlushHiveMetastoreCacheProcedure
implements Provider<Procedure>
{
private static final String PROCEDURE_NAME = "flush_metadata_cache";

private static final String PARAM_SCHEMA_NAME = "schema_name";
private static final String PARAM_TABLE_NAME = "table_name";
private static final String PARAM_PARTITION_COLUMN = "partition_column";
private static final String PARAM_PARTITION_VALUE = "partition_value";
private static final String PARAM_SCHEMA_NAME = "SCHEMA_NAME";
private static final String PARAM_TABLE_NAME = "TABLE_NAME";
private static final String PARAM_PARTITION_COLUMN = "PARTITION_COLUMN";
private static final String PARAM_PARTITION_VALUE = "PARTITION_VALUE";

private static final String PROCEDURE_USAGE_EXAMPLES = format(
"Valid usages:%n" +
" - '%1$s()'%n" +
" - %1$s(%2$s => ..., %3$s => ..., %4$s => ARRAY['...'], %5$s => ARRAY['...'])",
PROCEDURE_NAME,
PARAM_SCHEMA_NAME,
PARAM_TABLE_NAME,
PARAM_PARTITION_COLUMN,
PARAM_PARTITION_VALUE);
// Use lowercase parameter names per convention. In the usage example the names are not delimited.
PARAM_SCHEMA_NAME.toLowerCase(ENGLISH),
PARAM_TABLE_NAME.toLowerCase(ENGLISH),
PARAM_PARTITION_COLUMN.toLowerCase(ENGLISH),
PARAM_PARTITION_VALUE.toLowerCase(ENGLISH));

private static final MethodHandle FLUSH_HIVE_METASTORE_CACHE = methodHandle(
FlushHiveMetastoreCacheProcedure.class,
Expand All @@ -79,7 +81,7 @@ public Procedure get()
"system",
PROCEDURE_NAME,
ImmutableList.of(
new Procedure.Argument("$fake_first_parameter", VARCHAR, false, FAKE_PARAM_DEFAULT_VALUE),
new Procedure.Argument("$FAKE_FIRST_PARAMETER", VARCHAR, false, FAKE_PARAM_DEFAULT_VALUE),
new Procedure.Argument(PARAM_SCHEMA_NAME, VARCHAR, false, null),
new Procedure.Argument(PARAM_TABLE_NAME, VARCHAR, false, null),
new Procedure.Argument(PARAM_PARTITION_COLUMN, new ArrayType(VARCHAR), false, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public Procedure get()
"system",
"create_empty_partition",
ImmutableList.of(
new Argument("schema_name", VARCHAR),
new Argument("table_name", VARCHAR),
new Argument("partition_columns", new ArrayType(VARCHAR)),
new Argument("partition_values", new ArrayType(VARCHAR))),
new Argument("SCHEMA_NAME", VARCHAR),
new Argument("TABLE_NAME", VARCHAR),
new Argument("PARTITION_COLUMNS", new ArrayType(VARCHAR)),
new Argument("PARTITION_VALUES", new ArrayType(VARCHAR))),
CREATE_EMPTY_PARTITION.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public Procedure get()
"system",
"drop_stats",
ImmutableList.of(
new Argument("schema_name", VARCHAR),
new Argument("table_name", VARCHAR),
new Argument("partition_values", new ArrayType(new ArrayType(VARCHAR)), false, null)),
new Argument("SCHEMA_NAME", VARCHAR),
new Argument("TABLE_NAME", VARCHAR),
new Argument("PARTITION_VALUES", new ArrayType(new ArrayType(VARCHAR)), false, null)),
DROP_STATS.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public Procedure get()
"system",
"register_partition",
ImmutableList.of(
new Procedure.Argument("schema_name", VARCHAR),
new Procedure.Argument("table_name", VARCHAR),
new Procedure.Argument("partition_columns", new ArrayType(VARCHAR)),
new Procedure.Argument("partition_values", new ArrayType(VARCHAR)),
new Procedure.Argument("location", VARCHAR, false, null)),
new Procedure.Argument("SCHEMA_NAME", VARCHAR),
new Procedure.Argument("TABLE_NAME", VARCHAR),
new Procedure.Argument("PARTITION_COLUMNS", new ArrayType(VARCHAR)),
new Procedure.Argument("PARTITION_VALUES", new ArrayType(VARCHAR)),
new Procedure.Argument("LOCATION", VARCHAR, false, null)),
REGISTER_PARTITION.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public Procedure get()
"system",
"sync_partition_metadata",
ImmutableList.of(
new Argument("schema_name", VARCHAR),
new Argument("table_name", VARCHAR),
new Argument("mode", VARCHAR),
new Argument("case_sensitive", BOOLEAN, false, TRUE)),
new Argument("SCHEMA_NAME", VARCHAR),
new Argument("TABLE_NAME", VARCHAR),
new Argument("MODE", VARCHAR),
new Argument("CASE_SENSITIVE", BOOLEAN, false, TRUE)),
SYNC_PARTITION_METADATA.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public Procedure get()
"system",
"unregister_partition",
ImmutableList.of(
new Procedure.Argument("schema_name", VARCHAR),
new Procedure.Argument("table_name", VARCHAR),
new Procedure.Argument("partition_columns", new ArrayType(VARCHAR)),
new Procedure.Argument("partition_values", new ArrayType(VARCHAR))),
new Procedure.Argument("SCHEMA_NAME", VARCHAR),
new Procedure.Argument("TABLE_NAME", VARCHAR),
new Procedure.Argument("PARTITION_COLUMNS", new ArrayType(VARCHAR)),
new Procedure.Argument("PARTITION_VALUES", new ArrayType(VARCHAR))),
UNREGISTER_PARTITION.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7891,6 +7891,13 @@ public void testOptimize()
assertUpdate(optimizeEnabledSession, "ALTER TABLE " + tableName + " EXECUTE optimize(file_size_threshold => '10B')");
assertThat(getTableFiles(tableName)).hasSameElementsAs(compactedFiles);

// optimize with delimited procedure name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please separate tests for procedure name from tests for arguments (put them in different methods)? It seems that they are distinct issues. Also, could you add tests with unquoted names in different case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is just a smoke test coverage. I put the together because it's not a detailed test for ALTER TABLE EXECUTE itself. (such test doesn't exist, and I don't want to add it)

assertQueryFails(optimizeEnabledSession, "ALTER TABLE " + tableName + " EXECUTE \"optimize\"", "Procedure optimize not registered for catalog hive");
assertUpdate(optimizeEnabledSession, "ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\"");
// optimize with delimited parameter name (and procedure name)
assertUpdate(optimizeEnabledSession, "ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\" (\"file_size_threshold\" => '10B')"); // TODO (https://github.com/trinodb/trino/issues/11326) this should fail
assertUpdate(optimizeEnabledSession, "ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\" (\"FILE_SIZE_THRESHOLD\" => '10B')");

assertUpdate("DROP TABLE " + tableName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public Procedure get()
"system",
"rollback_to_snapshot",
ImmutableList.of(
new Procedure.Argument("schema", VARCHAR),
new Procedure.Argument("table", VARCHAR),
new Procedure.Argument("snapshot_id", BIGINT)),
new Procedure.Argument("SCHEMA", VARCHAR),
new Procedure.Argument("TABLE", VARCHAR),
new Procedure.Argument("SNAPSHOT_ID", BIGINT)),
ROLLBACK_TO_SNAPSHOT.bindTo(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,13 @@ public void testOptimize()
assertThat(getAllDataFilesFromTableDirectory(tableName))
.containsExactlyInAnyOrderElementsOf(concat(initialFiles, updatedFiles));

// optimize with delimited procedure name
assertQueryFails("ALTER TABLE " + tableName + " EXECUTE \"optimize\"", "Procedure optimize not registered for catalog iceberg");
assertUpdate("ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\"");
// optimize with delimited parameter name (and procedure name)
assertUpdate("ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\" (\"file_size_threshold\" => '33B')"); // TODO (https://github.com/trinodb/trino/issues/11326) this should fail
assertUpdate("ALTER TABLE " + tableName + " EXECUTE \"OPTIMIZE\" (\"FILE_SIZE_THRESHOLD\" => '33B')");

assertUpdate("DROP TABLE " + tableName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public Procedure getAddPartitionProcedure()
"system",
"add_range_partition",
ImmutableList.of(
new Argument("schema", VARCHAR),
new Argument("table", VARCHAR),
new Argument("range_bounds", VARCHAR)),
new Argument("SCHEMA", VARCHAR),
new Argument("TABLE", VARCHAR),
new Argument("RANGE_BOUNDS", VARCHAR)),
ADD.bindTo(this));
}

Expand All @@ -62,9 +62,9 @@ public Procedure getDropPartitionProcedure()
"system",
"drop_range_partition",
ImmutableList.of(
new Argument("schema", VARCHAR),
new Argument("table", VARCHAR),
new Argument("range_bounds", VARCHAR)),
new Argument("SCHEMA", VARCHAR),
new Argument("TABLE", VARCHAR),
new Argument("RANGE_BOUNDS", VARCHAR)),
DROP.bindTo(this));
}

Expand Down
Loading