yanxinyi commented on a change in pull request #972: URL: https://github.com/apache/phoenix/pull/972#discussion_r530100936
########## 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. Review comment: Can you provide an example of a legitimate long number? Do you mean when a value here is greater than the SHORT.MAX_VALUE? Yeah, if that's the case the value that we send back to the client will lose some data precision but still queryable. ---------------------------------------------------------------- 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: us...@infra.apache.org