[
https://issues.apache.org/jira/browse/PHOENIX-6519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17389777#comment-17389777
]
ASF GitHub Bot commented on PHOENIX-6519:
-----------------------------------------
richardantal commented on a change in pull request #1275:
URL: https://github.com/apache/phoenix/pull/1275#discussion_r678984841
##########
File path: phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
##########
@@ -1238,6 +1238,78 @@ public static String
getNormalizedColumnName(ColumnParseNode columnParseNode) {
return columnParseNode.getName();
}
+ public static String getFullTableNameWithQuotes(String schemaName, String
tableName,
+ boolean schemaNameCaseSensitive, boolean tableNameCaseSensitive) {
+ String fullTableName;
+
+ if (tableNameCaseSensitive) {
+ fullTableName = "\"" + tableName + "\"";
+ } else {
+ fullTableName = tableName;
+ }
+
+ if(schemaName != null && schemaName.length() != 0) {
+ if (schemaNameCaseSensitive) {
+ fullTableName = "\"" + schemaName + "\"" +
QueryConstants.NAME_SEPARATOR + fullTableName;
+ } else {
+ fullTableName = schemaName + QueryConstants.NAME_SEPARATOR +
fullTableName;
+ }
+ }
+ return fullTableName;
+ }
+
+ public static String getFullTableNameWithQuotes(String schemaName, String
tableName) {
+ return getFullTableNameWithQuotes(schemaName, tableName,
+ quotesNeededForSchema(schemaName),
quotesNeededForTable(tableName));
+ }
+
+ private static boolean quotesNeededForSchema(String name) {
+ if (Strings.isNullOrEmpty(name) ||
name.equals(QueryConstants.DEFAULT_COLUMN_FAMILY)) {
+ return false;
+ }
+ return quotesNeededForTable(name);
+ }
+
+ private static boolean quotesNeededForColumn(String name) {
+ if (!name.equals("_INDEX_ID") &&
"_".equals(String.valueOf(name.charAt(0)))) {
Review comment:
If we want to create a table named _FOO we need quotes around that. The
same applies for column names.
The difference is that when we create an index, _INDEX_ID column is added
automatically and we do not want to have quotes around that. (But it should be
possible to create a table called "_INDEX_ID" even if it an abnormal name.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Make SchemaTool work with lower case table and column names
> -----------------------------------------------------------
>
> Key: PHOENIX-6519
> URL: https://issues.apache.org/jira/browse/PHOENIX-6519
> Project: Phoenix
> Issue Type: Task
> Components: core
> Reporter: Richárd Antal
> Assignee: Richárd Antal
> Priority: Major
>
> I wrote this test as part of a PR for PHOENIX-6518 and it fails.
> {code:java}
> @Test
> public void testCreateTableStatementLowerCase() throws Exception {
> String tableName = "lowecasetbl1";
> String schemaName = "lowecaseschemaname1";
> String pTableFullName = SchemaUtil.getEscapedTableName(schemaName,
> tableName);
> String createTableStmt = "CREATE TABLE "+ pTableFullName +
> "(\"smallK\" VARCHAR NOT NULL PRIMARY KEY, "
> + "V1 VARCHAR, V2 VARCHAR) TTL=2592000, IMMUTABLE_ROWS=TRUE,
> DISABLE_WAL=TRUE";
> List<String> queries = new ArrayList<String>(){};
> queries.add(createTableStmt);
> String result = runSchemaExtractionTool("\"" + schemaName + "\"",
> "\"" + tableName + "\"", null, queries);
> Assert.assertEquals(createTableStmt, result.toUpperCase());
> }{code}
> Expected:
> {code:java}
> CREATE TABLE "lowecaseschemaname1"."lowecasetbl1"("smallK" VARCHAR NOT NULL
> PRIMARY KEY, V1 VARCHAR, V2 VARCHAR) TTL=2592000, IMMUTABLE_ROWS=TRUE,
> DISABLE_WAL=TRUE{code}
> Actual result:
> {code:java}
> CREATE TABLE LOWECASESCHEMANAME1.LOWECASETBL1(SMALLK VARCHAR NOT NULL PRIMARY
> KEY, V1 VARCHAR, V2 VARCHAR) TTL=2592000, IMMUTABLE_ROWS=TRUE,
> DISABLE_WAL=TRUE{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)