gokceni commented on a change in pull request #434: PHOENIX-5018 Index 
mutations created by UPSERT SELECT will have wrong…
URL: https://github.com/apache/phoenix/pull/434#discussion_r253676150
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/compile/ServerBuildIndexCompiler.java
 ##########
 @@ -0,0 +1,127 @@
+/*
+ * 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.compile;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.execute.MutationState;
+import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
+import org.apache.phoenix.index.IndexMaintainer;
+import org.apache.phoenix.index.PhoenixIndexCodec;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.schema.*;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.IndexUtil;
+import org.apache.phoenix.util.ScanUtil;
+import org.apache.phoenix.util.StringUtil;
+
+import com.google.common.collect.Lists;
+
+import static org.apache.phoenix.schema.types.PDataType.TRUE_BYTES;
+
+
+/**
+ * Class that compiles plan to generate initial data values after a DDL 
command for
+ * index table.
+ */
+public class ServerBuildIndexCompiler {
+    private final PhoenixConnection connection;
+    private final String tableName;
+    
+    public ServerBuildIndexCompiler(PhoenixConnection connection, String 
tableName) {
+        this.connection = connection;
+        this.tableName = tableName;
+    }
+
+    public MutationPlan compile(PTable index) throws SQLException {
+        try (final PhoenixStatement statement = new 
PhoenixStatement(connection)) {
+            String query = "SELECT count(*) FROM " + tableName;
+            final QueryPlan plan = statement.compileQuery(query);
+            TableRef tableRef = plan.getTableRef();
+            Scan scan = plan.getContext().getScan();
+            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+            final PTable dataTable = tableRef.getTable();
+            IndexMaintainer.serialize(dataTable, ptr, 
Collections.singletonList(index), plan.getContext().getConnection());
+            // Set attribute on scan that UngroupedAggregateRegionObserver 
will switch on.
+            // We'll detect that this attribute was set the server-side and 
write the index
+            // rows per region as a result. The value of the attribute will be 
our persisted
+            // index maintainers.
+            // Define the LOCAL_INDEX_BUILD as a new static in 
BaseScannerRegionObserver
 
 Review comment:
   nit: Could you add to the comment what is the attribute on scan to switch on 
UngroupedAggregateRegionObserver? 
   Also, the comment mentions LOCAL_INDEX_BUILD but in code 
LOCAL_INDEX_BUILD_PROTO is used. Is there a mismatch?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to