[
https://issues.apache.org/jira/browse/PHOENIX-6454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17339233#comment-17339233
]
ASF GitHub Bot commented on PHOENIX-6454:
-----------------------------------------
swaroopak commented on a change in pull request #1217:
URL: https://github.com/apache/phoenix/pull/1217#discussion_r626032856
##########
File path:
phoenix-tools/src/main/java/org/apache/phoenix/schema/SchemaSynthesisProcessor.java
##########
@@ -0,0 +1,261 @@
+/*
+ * 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.
+ */
+package org.apache.phoenix.schema;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.parse.AddColumnStatement;
+import org.apache.phoenix.parse.BindableStatement;
+import org.apache.phoenix.parse.ColumnDef;
+import org.apache.phoenix.parse.ColumnName;
+import org.apache.phoenix.parse.CreateIndexStatement;
+import org.apache.phoenix.parse.CreateTableStatement;
+import org.apache.phoenix.parse.DropColumnStatement;
+import org.apache.phoenix.parse.SQLParser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SchemaSynthesisProcessor extends SchemaProcessor {
+ public static final String
+ ENTITY_NAME_IN_BASE_AND_ALTER_DDL_DON_T_MATCH =
+ "Entity name in base and alter DDL don't match";
+ private final String baseDDLFile;
+ private final String alterDDLFile;
+
+ public SchemaSynthesisProcessor(String baseDDLFile, String alterDDLFile) {
+ this.baseDDLFile = baseDDLFile;
+ this.alterDDLFile = alterDDLFile;
+ }
+
+ @Override
+ public String process() throws Exception {
+ String baseDDL = getQueriesFromFile(baseDDLFile).get(0);
+ List <String> alterDDL = getQueriesFromFile(alterDDLFile);
+ for(String s : alterDDL) {
+ baseDDL = synthesize(baseDDL, s);
+ }
+ return baseDDL;
+ }
+
+ private String synthesize(String baseDDL, String alterDDL) throws
Exception {
+ BindableStatement createStatement = new
SQLParser(baseDDL).parseStatement();
+ BindableStatement alterStatement = new
SQLParser(alterDDL).parseStatement();
+ if (createStatement instanceof CreateTableStatement) {
+ CreateTableStatement newCreateStmt = null;
+ CreateTableStatement createStmt = (CreateTableStatement)
createStatement;
+ if (alterStatement instanceof AddColumnStatement) {
+ newCreateStmt =
+ getCreateTableStatement((AddColumnStatement)
alterStatement, createStmt);
+ } else if(alterStatement instanceof DropColumnStatement) {
+ newCreateStmt =
+ getCreateTableStatement((DropColumnStatement)
alterStatement, createStmt);
+ }
+ return getCreateTableSQL(newCreateStmt);
+ } else if (createStatement instanceof CreateIndexStatement) {
+ CreateIndexStatement newCreateIndexStmt =
+ getCreateIndexStatement((CreateIndexStatement)
createStatement, alterStatement);
+ return getCreateIndexSQL(newCreateIndexStmt);
+ }
+ return "";
+ }
+
+ private CreateIndexStatement getCreateIndexStatement(CreateIndexStatement
createStatement,
+ BindableStatement alterStatement) throws Exception {
+ CreateIndexStatement newCreateIndexStmt = null;
+ String tableName = createStatement.getIndexTableName().toString();
+ String tableNameInAlter =
((AddColumnStatement)alterStatement).getTable().toString().trim();
Review comment:
In the case of indexes, the alter statement will be mainly for altering
properties which is a special case in AddColumnStatement. We cant drop/add a
column to the index. So it is safe to cast it to AddColumnStatement.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add feature to SchemaTool to get the DDL in specification mode
> --------------------------------------------------------------
>
> Key: PHOENIX-6454
> URL: https://issues.apache.org/jira/browse/PHOENIX-6454
> Project: Phoenix
> Issue Type: Improvement
> Reporter: Swaroopa Kadam
> Assignee: Swaroopa Kadam
> Priority: Major
> Fix For: 4.17.0, 5.2.0
>
>
> Currently, SchemExtractionTool uses PTable representation to get the
> effective DDL on the cluster.
> Rename SchemaExtractionTool to SchemaTool, add a feature that accepts create
> DDL and alter DDL to give effective DDL without using PTable implementation.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)