Skip to content

Commit de29dd0

Browse files
palashcPalash Chauhan
and
Palash Chauhan
authoredMar 21, 2025
PHOENIX-7552 : Escape bloomfilter value and column family in SchemaTool synthesis (#2094)
Co-authored-by: Palash Chauhan <p.chauhan@pchauha-ltmgv47.internal.salesforce.com>
1 parent b1706df commit de29dd0

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed
 

‎phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaSQLUtil.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ private static String getColumnDefListToString(CreateTableStatement createStatem
112112
}
113113

114114
private static String getColumnInfoString(ColumnDef cDef) {
115+
String colFam = cDef.getColumnDefName().getFamilyName();
116+
String colDefName = cDef.getColumnDefName().getColumnName();
115117
String colName = cDef.getColumnDefName().toString();
118+
if (colFam != null) {
119+
colName = SchemaUtil.getEscapedArgument(colFam)
120+
+ "." + SchemaUtil.getEscapedArgument(colDefName);
121+
}
116122
boolean isArrayType = cDef.getDataType().isArrayType();
117123
String type = cDef.getDataType().getSqlTypeName();
118124
Integer maxLength = cDef.getMaxLength();
@@ -169,8 +175,13 @@ private static void appendProperties(StringBuffer sb,
169175
if (prop.contains(".")) {
170176
prop = SchemaUtil.getEscapedArgument(prop);
171177
}
172-
sb.append(prop).append("=")
173-
.append(entry.getValue().getSecond());
178+
if (prop.equals("BLOOMFILTER")) {
179+
sb.append(prop).append("=")
180+
.append("'").append(entry.getValue().getSecond()).append("'");
181+
} else {
182+
sb.append(prop).append("=")
183+
.append(entry.getValue().getSecond());
184+
}
174185
sb.append(",");
175186
}
176187
sb.deleteCharAt(sb.length()-1);

‎phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolSynthesisIT.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,21 @@ public void testEscapedPropertyName() throws Exception {
234234
"(ORGANIZATION_ID CHAR(15) NOT NULL,\n" +
235235
"NETWORK_ID CHAR(15) NOT NULL\n" +
236236
"CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID))\n" +
237-
"UPDATE_CACHE_FREQUENCY=172800000,DISABLE_BACKUP=true,MULTI_TENANT=true,REPLICATION_SCOPE=1,\"phoenix.max.lookback.age.seconds\"=0,VERSIONS=1";
237+
"BLOOMFILTER='ROW',UPDATE_CACHE_FREQUENCY=172800000,DISABLE_BACKUP=true,MULTI_TENANT=true,REPLICATION_SCOPE=1,\"phoenix.max.lookback.age.seconds\"=0,VERSIONS=1";
238238
String baseDDL = filePath+"/escape_property.sql";
239239
runAndVerify(expected, baseDDL);
240240
}
241+
242+
@Test
243+
public void testEscapedColumnName() throws Exception {
244+
String expected = "CREATE TABLE IF NOT EXISTS ABC\n" +
245+
"(NID CHAR(15) NOT NULL,\n" +
246+
"DATA VARCHAR,\n" +
247+
"\"a\".\"_\" CHAR(1),\n" +
248+
"\"b\".\"_\" CHAR(1)\n" +
249+
"CONSTRAINT PK PRIMARY KEY (NID))\n" +
250+
"BLOOMFILTER='ROW',UPDATE_CACHE_FREQUENCY=172800000,DISABLE_BACKUP=true,MULTI_TENANT=true,REPLICATION_SCOPE=1,\"phoenix.max.lookback.age.seconds\"=0,VERSIONS=1";
251+
String baseDDL = filePath+"/escape_column.sql";
252+
runAndVerify(expected, baseDDL);
253+
}
241254
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
CREATE TABLE IF NOT EXISTS ABC (NID CHAR(15) NOT NULL, DATA VARCHAR, "a"."_" char(1),
19+
"b"."_" char(1) CONSTRAINT PK PRIMARY KEY (NID)) VERSIONS=1,MULTI_TENANT=true,REPLICATION_SCOPE=1;
20+
ALTER TABLE ABC SET DISABLE_BACKUP=TRUE;
21+
ALTER TABLE ABC SET BLOOMFILTER='ROW';
22+
ALTER TABLE ABC SET "phoenix.max.lookback.age.seconds"=0;
23+
ALTER TABLE ABC SET UPDATE_CACHE_FREQUENCY=172800000;

‎phoenix-core/src/it/resources/synthesis/escape_property.sql

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
*/
1818
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;
1919
ALTER TABLE ABC SET DISABLE_BACKUP=TRUE;
20+
ALTER TABLE ABC SET BLOOMFILTER='ROW';
2021
ALTER TABLE ABC SET "phoenix.max.lookback.age.seconds"=0;
2122
ALTER TABLE ABC SET UPDATE_CACHE_FREQUENCY=172800000;

0 commit comments

Comments
 (0)
Please sign in to comment.