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

Quote column name in Phoenix CREATE TABLE statement #3601

Merged
merged 1 commit into from
Oct 7, 2020
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 @@ -143,6 +143,7 @@
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SKIP_REGION_BOUNDARY_CHECK;
import static org.apache.phoenix.util.PhoenixRuntime.getTable;
import static org.apache.phoenix.util.SchemaUtil.ESCAPE_CHARACTER;
import static org.apache.phoenix.util.SchemaUtil.getEscapedArgument;

public class PhoenixClient
extends BaseJdbcClient
Expand Down Expand Up @@ -389,7 +390,7 @@ public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, Connecto
typeStatement += " not null";
pkNames.add(columnName);
}
columnList.add(format("%s %s", columnName, typeStatement));
columnList.add(format("%s %s", getEscapedArgument(columnName), typeStatement));
}

ImmutableList.Builder<String> tableOptions = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public void testCreateSchema()
}

@Override
public void testColumnName(String columnName)
protected boolean isColumnNameRejected(Exception exception, String columnName, boolean delimited)
{
// TODO (https://github.com/prestosql/presto/issues/3466) Phoenix generally lacks quoting in underlying queries
throw new SkipException("TODO");
// TODO This should produce a reasonable exception message like "Invalid column name". Then, we should verify the actual exception message
return columnName.equals("a\"quote");
Copy link
Member

Choose a reason for hiding this comment

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

Leave some TODO comment still.
Currently the " in column name leads to SQL injection.
Use of a"quote column should produce a reasonable exception message like "Invalid column name" or "Column name cannot contain a quotation sign". Then, here you should verify the actual exception message.

}

@Override
Expand Down