Github user m2je commented on a diff in the pull request: https://github.com/apache/phoenix/pull/317#discussion_r206715609 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java --- @@ -1431,11 +1438,42 @@ private PTable getTable(RegionScanner scanner, long clientTimeStamp, long tableT // server while holding this lock is a bad idea and likely to cause contention. return PTableImpl.makePTable(tenantId, schemaName, tableName, tableType, indexState, timeStamp, tableSeqNum, pkName, saltBucketNum, columns, parentSchemaName, parentTableName, indexes, isImmutableRows, physicalTables, defaultFamilyName, - viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, + viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexType, viewIndexId, indexType, rowKeyOrderOptimizable, transactionProvider, updateCacheFrequency, baseColumnCount, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, encodingScheme, cqCounter, useStatsForParallelization); } + private Long getViewIndexId(Cell[] tableKeyValues, PDataType viewIndexType) { + Cell viewIndexIdKv = tableKeyValues[VIEW_INDEX_ID_INDEX]; + return viewIndexIdKv == null ? null : + decodeViewIndexId(viewIndexIdKv, viewIndexType); + } + /** + * check the value for {@value USE_LONG_VIEW_INDEX} and if its present consider viewIndexId as long otherwise + * read as short and convert it to long + * + * @param tableKeyValues + * @param viewIndexType + * @return + */ + private Long decodeViewIndexId(Cell viewIndexIdKv, PDataType viewIndexType) { + boolean useLongViewIndex = MetaDataUtil.getViewIndexIdDataType().equals(viewIndexType); + return new Long( + useLongViewIndex + ? viewIndexType.getCodec().decodeLong(viewIndexIdKv.getValueArray(), + viewIndexIdKv.getValueOffset(), SortOrder.getDefault()) + : MetaDataUtil.getLegacyViewIndexIdDataType().getCodec().decodeShort(viewIndexIdKv.getValueArray(), + viewIndexIdKv.getValueOffset(), SortOrder.getDefault()) + ); + } + + private PDataType getViewIndexType(Cell[] tableKeyValues) { + Cell useLongViewIndexKv = tableKeyValues[USE_LONG_VIEW_INDEX]; --- End diff -- done
---