ChinmaySKulkarni commented on a change in pull request #972: URL: https://github.com/apache/phoenix/pull/972#discussion_r530041005
########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { + private String ddlForBaseTable = "CREATE TABLE %s (TENANT_ID CHAR(15) NOT NULL, ID CHAR(3)" + Review comment: nit: Can we make all of these static final Strings? ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { + private String ddlForBaseTable = "CREATE TABLE %s (TENANT_ID CHAR(15) NOT NULL, ID CHAR(3)" + + " NOT NULL, NUM BIGINT CONSTRAINT PK PRIMARY KEY (TENANT_ID, ID))" + + " MULTI_TENANT = true, COLUMN_ENCODED_BYTES=0 "; + private String ddlForView = "CREATE VIEW %s (A BIGINT PRIMARY KEY, B BIGINT)" + + " AS SELECT * FROM %s WHERE ID='ABC'"; + private String ddlForViewIndex = + "CREATE INDEX %s ON %s (B DESC) INCLUDE (NUM)"; + private String selectAll = "SELECT * FROM SYSTEM.CATALOG"; + private String selectRow = "SELECT VIEW_INDEX_ID,VIEW_INDEX_ID_DATA_TYPE" + Review comment: nit: Since these Strings are constants, by convention we can snake case capitalize them. ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { Review comment: Can you add a class-level comment and mention the JIRA(s) involved in this for more context ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { + private String ddlForBaseTable = "CREATE TABLE %s (TENANT_ID CHAR(15) NOT NULL, ID CHAR(3)" + + " NOT NULL, NUM BIGINT CONSTRAINT PK PRIMARY KEY (TENANT_ID, ID))" + + " MULTI_TENANT = true, COLUMN_ENCODED_BYTES=0 "; + private String ddlForView = "CREATE VIEW %s (A BIGINT PRIMARY KEY, B BIGINT)" + + " AS SELECT * FROM %s WHERE ID='ABC'"; + private String ddlForViewIndex = + "CREATE INDEX %s ON %s (B DESC) INCLUDE (NUM)"; + private String selectAll = "SELECT * FROM SYSTEM.CATALOG"; + private String selectRow = "SELECT VIEW_INDEX_ID,VIEW_INDEX_ID_DATA_TYPE" + + " FROM SYSTEM.CATALOG WHERE TABLE_NAME='%s' AND COLUMN_COUNT IS NOT NULL"; + + @BeforeClass + public static void setUp() throws Exception { + Map<String, String> props = Maps.newHashMapWithExpectedSize(1); + props.put(ScanInfoUtil.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, Integer.toString(60*60)); + setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); + } + + @Test + public void testSelectViewIndexIdAsLong() throws Exception { + testSelectViewIndexId(true); + } + + @Test + public void testSelectViewIndexIdAsShort() throws Exception { + testSelectViewIndexId(false); + } + + private void testSelectViewIndexId(boolean isTestingLongViewIndexId) throws Exception { + String val = isTestingLongViewIndexId ? "true" : "false"; + int expectedDataType = isTestingLongViewIndexId ? Types.BIGINT : Types.SMALLINT; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, val); + String schema = generateUniqueName(); + String baseTable = generateUniqueName(); + String fullTableName = SchemaUtil.getTableName(schema, baseTable); + String viewName = generateUniqueName(); + String viewFullName = SchemaUtil.getTableName(schema, viewName); + String viewIndexName = generateUniqueName(); + try (final Connection conn = DriverManager.getConnection(url,props); + final Statement stmt = conn.createStatement()) { + stmt.execute(String.format(ddlForBaseTable, fullTableName)); + stmt.execute(String.format(ddlForView, viewFullName, fullTableName)); + stmt.execute(String.format(ddlForViewIndex, viewIndexName, viewFullName)); + + ResultSet rs = stmt.executeQuery(String.format(selectRow, viewIndexName)); + rs.next(); + assertEquals(Short.MIN_VALUE,rs.getLong(1)); Review comment: Even when the `LONG_VIEW_INDEX_ENABLED_ATTRIB ` config is set to long, we expect Short.MIN_VALUE to allow clients to switch the config (as we discussed offline). Can you add a comment about this in the test? ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { + private String ddlForBaseTable = "CREATE TABLE %s (TENANT_ID CHAR(15) NOT NULL, ID CHAR(3)" + + " NOT NULL, NUM BIGINT CONSTRAINT PK PRIMARY KEY (TENANT_ID, ID))" + + " MULTI_TENANT = true, COLUMN_ENCODED_BYTES=0 "; + private String ddlForView = "CREATE VIEW %s (A BIGINT PRIMARY KEY, B BIGINT)" + + " AS SELECT * FROM %s WHERE ID='ABC'"; + private String ddlForViewIndex = + "CREATE INDEX %s ON %s (B DESC) INCLUDE (NUM)"; + private String selectAll = "SELECT * FROM SYSTEM.CATALOG"; + private String selectRow = "SELECT VIEW_INDEX_ID,VIEW_INDEX_ID_DATA_TYPE" + + " FROM SYSTEM.CATALOG WHERE TABLE_NAME='%s' AND COLUMN_COUNT IS NOT NULL"; + + @BeforeClass + public static void setUp() throws Exception { + Map<String, String> props = Maps.newHashMapWithExpectedSize(1); + props.put(ScanInfoUtil.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, Integer.toString(60*60)); + setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); + } + + @Test + public void testSelectViewIndexIdAsLong() throws Exception { + testSelectViewIndexId(true); + } + + @Test + public void testSelectViewIndexIdAsShort() throws Exception { + testSelectViewIndexId(false); + } + + private void testSelectViewIndexId(boolean isTestingLongViewIndexId) throws Exception { + String val = isTestingLongViewIndexId ? "true" : "false"; + int expectedDataType = isTestingLongViewIndexId ? Types.BIGINT : Types.SMALLINT; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, val); + String schema = generateUniqueName(); + String baseTable = generateUniqueName(); + String fullTableName = SchemaUtil.getTableName(schema, baseTable); + String viewName = generateUniqueName(); + String viewFullName = SchemaUtil.getTableName(schema, viewName); + String viewIndexName = generateUniqueName(); + try (final Connection conn = DriverManager.getConnection(url,props); + final Statement stmt = conn.createStatement()) { + stmt.execute(String.format(ddlForBaseTable, fullTableName)); + stmt.execute(String.format(ddlForView, viewFullName, fullTableName)); + stmt.execute(String.format(ddlForViewIndex, viewIndexName, viewFullName)); + + ResultSet rs = stmt.executeQuery(String.format(selectRow, viewIndexName)); + rs.next(); + assertEquals(Short.MIN_VALUE,rs.getLong(1)); + assertEquals(expectedDataType, rs.getInt(2)); + assertFalse(rs.next()); + } + } + + @Test + public void testMixedCase() throws Exception { + // mixed case + Properties propsForLongType = PropertiesUtil.deepCopy(TEST_PROPERTIES); + propsForLongType.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, "true"); + String schema = generateUniqueName(); + String baseTable = generateUniqueName(); + String fullTableName = SchemaUtil.getTableName(schema, baseTable); + String viewName = generateUniqueName(); + String viewFullName = SchemaUtil.getTableName(schema, viewName); + String viewIndexName1 = generateUniqueName(); + + // view index id data type is long + try (final Connection conn = DriverManager.getConnection(url,propsForLongType); + final Statement stmt = conn.createStatement()) { + stmt.execute(String.format(ddlForBaseTable, fullTableName)); + stmt.execute(String.format(ddlForView, viewFullName, fullTableName)); + stmt.execute(String.format(ddlForViewIndex, viewIndexName1, viewFullName)); + + ResultSet rs = stmt.executeQuery(String.format(selectRow, viewIndexName1)); + rs.next(); + assertEquals(Short.MIN_VALUE,rs.getLong(1)); + assertEquals(Types.BIGINT, rs.getInt(2)); + assertFalse(rs.next()); + } + + // view index id data type is short + String viewIndexName2 = generateUniqueName(); + Properties propsForShortType = PropertiesUtil.deepCopy(TEST_PROPERTIES); + propsForShortType.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, "false"); + try (final Connection conn = DriverManager.getConnection(url,propsForShortType); + final Statement stmt = conn.createStatement()) { + stmt.execute(String.format(ddlForViewIndex, viewIndexName2, viewFullName)); + + ResultSet rs = stmt.executeQuery(String.format(selectRow, viewIndexName2)); + rs.next(); + assertEquals(Short.MIN_VALUE + 1,rs.getLong(1)); + assertEquals(Types.SMALLINT, rs.getInt(2)); + assertFalse(rs.next()); + } + + // check select * from syscat + try (final Connection conn = DriverManager.getConnection(url); + final Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery(String.format(selectAll)); Review comment: Why not just query for the exact metadata rows for the view indices instead of select * . ########## File path: phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java ########## @@ -17,8 +17,14 @@ */ package org.apache.phoenix.compile; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; import static org.apache.phoenix.query.QueryServices.WILDCARD_QUERY_DYNAMIC_COLS_ATTRIB; import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_WILDCARD_QUERY_DYNAMIC_COLS_ATTRIB; +import static org.apache.phoenix.schema.types.PDataType.TRUE_BYTES; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.SYSCATA_COPROC_IGNORE_TAG; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.SYSCATA_COPROC_IGNORE_BYTE; Review comment: These imports look unused. Please remove ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java ########## @@ -0,0 +1,169 @@ +/* + * 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.end2end; + +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; +import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Types; +import java.util.Map; +import java.util.Properties; + +import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.regionserver.ScanInfoUtil; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT { Review comment: Since you need to query `SYSTEM.CATALOG` we would need to make this test use its own mini-cluster to prevent flapping in case of other parallel test runs ########## File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SyscatRegionObserver.java ########## @@ -0,0 +1,54 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.phoenix.filter.SyscatViewIndexIdFilter; +import org.apache.phoenix.util.ScanUtil; + +import java.io.IOException; + +import static org.apache.phoenix.util.ScanUtil.UNKNOWN_CLIENT_VERSION; + +/** + * Coprocessor that checks whether the VIEW_INDEX_ID needs to retrieve. + */ +public class SyscatRegionObserver extends BaseRegionObserver { Review comment: Can we rename this coproc so it indicates that it is for view_index_id queries on system.catalog instead of this generic name? ########## File path: phoenix-core/src/main/java/org/apache/phoenix/filter/SyscatViewIndexIdFilter.java ########## @@ -0,0 +1,131 @@ +/* + * 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.filter; + +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.hadoop.hbase.filter.FilterBase; +import org.apache.hadoop.hbase.util.Writables; +import org.apache.hadoop.io.Writable; +import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder; +import org.apache.phoenix.schema.SortOrder; +import org.apache.phoenix.schema.types.PInteger; +import org.apache.phoenix.util.KeyValueUtil; +import org.apache.phoenix.util.ViewIndexIdRetrieveUtil; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.sql.Types; +import java.util.Collections; +import java.util.List; + + +import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SPLITTABLE_SYSTEM_CATALOG; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_BYTES; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE_BYTES; +import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.NULL_DATA_TYPE_VALUE; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.VIEW_INDEX_ID_BIGINT_TYPE_PTR_LEN; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.VIEW_INDEX_ID_SMALLINT_TYPE_VALUE_LEN; + +public class SyscatViewIndexIdFilter extends FilterBase implements Writable { + private int clientVersion; + + public SyscatViewIndexIdFilter() { + } + + public SyscatViewIndexIdFilter(int clientVersion) { + this.clientVersion = clientVersion; + } + + @Override + public ReturnCode filterKeyValue(Cell keyValue) { + return ReturnCode.INCLUDE_AND_NEXT_COL; + } + + @Override + public boolean hasFilterRow() { + return true; + } + + @Override + public void filterRowCells(List<Cell> kvs) throws IOException { + Cell viewIndexIdCell = KeyValueUtil.getColumnLatest( + GenericKeyValueBuilder.INSTANCE, kvs, + DEFAULT_COLUMN_FAMILY_BYTES, VIEW_INDEX_ID_BYTES); + + if (viewIndexIdCell != null) { + int type = NULL_DATA_TYPE_VALUE; + Cell viewIndexIdDataTypeCell = KeyValueUtil.getColumnLatest( + GenericKeyValueBuilder.INSTANCE, kvs, + DEFAULT_COLUMN_FAMILY_BYTES, VIEW_INDEX_ID_DATA_TYPE_BYTES); + if (viewIndexIdDataTypeCell != null) { + type = (Integer) PInteger.INSTANCE.toObject( + viewIndexIdDataTypeCell.getValueArray(), + viewIndexIdDataTypeCell.getValueOffset(), + viewIndexIdDataTypeCell.getValueLength(), + PInteger.INSTANCE, + SortOrder.ASC); + } + if (this.clientVersion < MIN_SPLITTABLE_SYSTEM_CATALOG) { + // pre-splittable client should always using SMALLINT + if (type == NULL_DATA_TYPE_VALUE && viewIndexIdCell.getValueLength() > + VIEW_INDEX_ID_SMALLINT_TYPE_VALUE_LEN) { + Cell keyValue = ViewIndexIdRetrieveUtil. + getViewIndexIdKeyValueInShortDataFormat(viewIndexIdCell); + Collections.replaceAll(kvs, viewIndexIdCell, keyValue); + } + } else { + // post-splittable client should always using BIGINT + if (type != Types.BIGINT && viewIndexIdCell.getValueLength() < Review comment: Let's add comments for these various conditions ########## File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SyscatRegionObserver.java ########## @@ -0,0 +1,54 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.phoenix.filter.SyscatViewIndexIdFilter; +import org.apache.phoenix.util.ScanUtil; + +import java.io.IOException; + +import static org.apache.phoenix.util.ScanUtil.UNKNOWN_CLIENT_VERSION; + +/** + * Coprocessor that checks whether the VIEW_INDEX_ID needs to retrieve. + */ +public class SyscatRegionObserver extends BaseRegionObserver { + @Override public void start(CoprocessorEnvironment e) throws IOException { + super.start(e); + } + + @Override public void stop(CoprocessorEnvironment e) throws IOException { + super.stop(e); + } + + @Override + public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan, + RegionScanner s) throws IOException { + int clientVersion = ScanUtil.getClientVersion(scan); + if (clientVersion != UNKNOWN_CLIENT_VERSION) { Review comment: nit: Not sure I understand why we don't care about 4.4.0 clients (not that it matters really). What is it for? ########## File path: phoenix-core/src/main/java/org/apache/phoenix/filter/SyscatViewIndexIdFilter.java ########## @@ -0,0 +1,131 @@ +/* + * 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.filter; + +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.hadoop.hbase.filter.FilterBase; +import org.apache.hadoop.hbase.util.Writables; +import org.apache.hadoop.io.Writable; +import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder; +import org.apache.phoenix.schema.SortOrder; +import org.apache.phoenix.schema.types.PInteger; +import org.apache.phoenix.util.KeyValueUtil; +import org.apache.phoenix.util.ViewIndexIdRetrieveUtil; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.sql.Types; +import java.util.Collections; +import java.util.List; + + +import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SPLITTABLE_SYSTEM_CATALOG; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_BYTES; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE_BYTES; +import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.NULL_DATA_TYPE_VALUE; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.VIEW_INDEX_ID_BIGINT_TYPE_PTR_LEN; +import static org.apache.phoenix.util.ViewIndexIdRetrieveUtil.VIEW_INDEX_ID_SMALLINT_TYPE_VALUE_LEN; + +public class SyscatViewIndexIdFilter extends FilterBase implements Writable { Review comment: nit: Rename to "SystemCatalog..." instead of "SysCat.." ---------------------------------------------------------------- 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]
