This is an automated email from the ASF dual-hosted git repository.

tkhurana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a12b28565 PHOENIX-7410 : Escape metadata attribute values/property 
names in SchemaTool synthesis (#1983)
0a12b28565 is described below

commit 0a12b2856565edcb80bed799bfede9879b0ab6b3
Author: Palash Chauhan <[email protected]>
AuthorDate: Mon Sep 30 09:51:02 2024 -0700

    PHOENIX-7410 : Escape metadata attribute values/property names in 
SchemaTool synthesis (#1983)
    
    * escape property names in schema tool synth
    
    * add license
    
    ---------
    
    Co-authored-by: Palash Chauhan 
<[email protected]>
---
 .../apache/phoenix/schema/tool/SchemaSQLUtil.java   |  7 ++++++-
 .../phoenix/schema/tool/SchemaToolSynthesisIT.java  | 14 ++++++++++++++
 .../src/it/resources/synthesis/escape_property.sql  | 21 +++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaSQLUtil.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaSQLUtil.java
index b89ae0a6be..5ce73cb8f1 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaSQLUtil.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaSQLUtil.java
@@ -25,6 +25,7 @@ import org.apache.phoenix.parse.CreateIndexStatement;
 import org.apache.phoenix.parse.CreateTableStatement;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.util.SchemaUtil;
 
 import java.util.List;
 import java.util.Map;
@@ -164,7 +165,11 @@ public class SchemaSQLUtil {
         if (props != null && !props.isEmpty()) {
             sb.append("\n");
             for (Map.Entry<String, Pair<String, Object>> entry : 
props.entries()) {
-                sb.append(entry.getValue().getFirst()).append("=")
+                String prop = entry.getValue().getFirst();
+                if (prop.contains(".")) {
+                    prop = SchemaUtil.getEscapedArgument(prop);
+                }
+                sb.append(prop).append("=")
                         .append(entry.getValue().getSecond());
                 sb.append(",");
             }
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolSynthesisIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolSynthesisIT.java
index 76df6377df..6d85d6c703 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolSynthesisIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolSynthesisIT.java
@@ -17,8 +17,10 @@
  */
 package org.apache.phoenix.schema.tool;
 
+import org.apache.phoenix.end2end.ParallelStatsEnabledTest;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import java.io.File;
 import java.net.URL;
@@ -27,6 +29,7 @@ import static 
org.apache.phoenix.schema.tool.SchemaSynthesisProcessor.ENTITY_NAM
 import static 
org.apache.phoenix.schema.tool.SchemaSynthesisProcessor.UNSUPPORTED_DDL_EXCEPTION;
 import static 
org.apache.phoenix.schema.tool.SchemaToolExtractionIT.runSchemaTool;
 
+@Category(ParallelStatsEnabledTest.class)
 public class SchemaToolSynthesisIT {
 
     private static final String SYNTHESIS_DIR = "synthesis/";
@@ -224,4 +227,15 @@ public class SchemaToolSynthesisIT {
             e.getMessage().equalsIgnoreCase(UNSUPPORTED_DDL_EXCEPTION);
         }
     }
+
+    @Test
+    public void testEscapedPropertyName() throws Exception {
+        String expected = "CREATE TABLE IF NOT EXISTS ABC\n" +
+                "(ORGANIZATION_ID CHAR(15) NOT NULL,\n" +
+                "NETWORK_ID CHAR(15) NOT NULL\n" +
+                "CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID))\n" +
+                
"UPDATE_CACHE_FREQUENCY=172800000,DISABLE_BACKUP=true,MULTI_TENANT=true,REPLICATION_SCOPE=1,\"phoenix.max.lookback.age.seconds\"=0,VERSIONS=1";
+        String baseDDL = filePath+"/escape_property.sql";
+        runAndVerify(expected, baseDDL);
+    }
 }
diff --git a/phoenix-core/src/it/resources/synthesis/escape_property.sql 
b/phoenix-core/src/it/resources/synthesis/escape_property.sql
new file mode 100644
index 0000000000..ce266161b1
--- /dev/null
+++ b/phoenix-core/src/it/resources/synthesis/escape_property.sql
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+CREATE TABLE IF NOT EXISTS ABC (ORGANIZATION_ID CHAR(15) NOT NULL, NETWORK_ID 
CHAR(15) NOT NULL, CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID)) 
VERSIONS=1,MULTI_TENANT=true,REPLICATION_SCOPE=1;
+ALTER TABLE ABC SET DISABLE_BACKUP=TRUE;
+ALTER TABLE ABC SET "phoenix.max.lookback.age.seconds"=0;
+ALTER TABLE ABC SET UPDATE_CACHE_FREQUENCY=172800000;
\ No newline at end of file

Reply via email to