public static PTable createFromProto()

in phoenix-core-client/src/main/java/org/apache/phoenix/schema/PTableImpl.java [1885:2140]


    public static PTable createFromProto(PTableProtos.PTable table) {
        if (table==null)
            return null;
        PName tenantId = null;
        if(table.hasTenantId()){
            tenantId = PNameFactory.newName(table.getTenantId().toByteArray());
        }
        PName schemaName = PNameFactory.newName(table.getSchemaNameBytes().toByteArray());
        PName tableName = PNameFactory.newName(table.getTableNameBytes().toByteArray());
        PName physicalTableName = null;
        if (table.getPhysicalTableNameBytes() != null) {
            physicalTableName = PNameFactory.newName(table.getPhysicalTableNameBytes().toByteArray());
        }
        PTableType tableType = PTableType.values()[table.getTableType().ordinal()];
        PIndexState indexState = null;
        if (table.hasIndexState()) {
            indexState = PIndexState.fromSerializedValue(table.getIndexState());
        }
        Long viewIndexId = null;
        if (table.hasViewIndexId()) {
            viewIndexId = table.getViewIndexId();
        }
        PDataType viewIndexIdType = table.hasViewIndexIdType()
                ? PDataType.fromTypeId(table.getViewIndexIdType())
                : MetaDataUtil.getLegacyViewIndexIdDataType();
        IndexType indexType = IndexType.getDefault();
        if(table.hasIndexType()){
            indexType = IndexType.fromSerializedValue(table.getIndexType().toByteArray()[0]);
        }
        long sequenceNumber = table.getSequenceNumber();
        long timeStamp = table.getTimeStamp();
        long indexDisableTimestamp = table.getIndexDisableTimestamp();
        PName pkName = null;
        if (table.hasPkNameBytes()) {
            pkName = PNameFactory.newName(table.getPkNameBytes().toByteArray());
        }
        int bucketNum = table.getBucketNum();
        List<PColumn> columns = Lists.newArrayListWithExpectedSize(table.getColumnsCount());
        for (PTableProtos.PColumn curPColumnProto : table.getColumnsList()) {
            columns.add(PColumnImpl.createFromProto(curPColumnProto));
        }
        List<PTable> indexes = Lists.newArrayListWithExpectedSize(table.getIndexesCount());
        for (PTableProtos.PTable curPTableProto : table.getIndexesList()) {
            indexes.add(createFromProto(curPTableProto));
        }

        PTable transformingNewTable = null;
        if (table.hasTransformingNewTable()){
            PTableProtos.PTable curTransformingPTableProto = table.getTransformingNewTable();
            transformingNewTable = createFromProto(curTransformingPTableProto);
        }
        boolean isImmutableRows = table.getIsImmutableRows();
        PName parentSchemaName = null;
        PName parentTableName = null;
        PName parentLogicalName = null;
        if (table.hasParentNameBytes()) {
            parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName((table.getParentNameBytes().toByteArray())));
            parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(table.getParentNameBytes().toByteArray()));
        }
        if (table.getBaseTableLogicalNameBytes() != null) {
            parentLogicalName = PNameFactory.newName(table.getBaseTableLogicalNameBytes().toByteArray());
        }
        PName defaultFamilyName = null;
        if (table.hasDefaultFamilyName()) {
            defaultFamilyName = PNameFactory.newName(table.getDefaultFamilyName().toByteArray());
        }
        boolean disableWAL = table.getDisableWAL();
        boolean multiTenant = table.getMultiTenant();
        boolean storeNulls = table.getStoreNulls();
        TransactionFactory.Provider transactionProvider = null;
        if (table.hasTransactionProvider()) {
            transactionProvider = TransactionFactory.Provider.fromCode(table.getTransactionProvider());
        } else if (table.hasTransactional()) {
            // For backward compatibility prior to transactionProvider field
            transactionProvider = TransactionFactory.Provider.NOTAVAILABLE;
        }
        ViewType viewType = null;
        String viewStatement = null;
        if (tableType == PTableType.VIEW) {
            viewType = ViewType.fromSerializedValue(table.getViewType().toByteArray()[0]);
        }
        if(table.hasViewStatement()){
            viewStatement = (String) PVarchar.INSTANCE.toObject(table.getViewStatement().toByteArray());
        }
        List<PName> physicalNames = Lists.newArrayListWithExpectedSize(table.getPhysicalNamesCount());
        for(int i = 0; i < table.getPhysicalNamesCount(); i++) {
            physicalNames.add(PNameFactory.newName(table.getPhysicalNames(i).toByteArray()));
        }
        int baseColumnCount = -1;
        if (table.hasBaseColumnCount()) {
            baseColumnCount = table.getBaseColumnCount();
        }

        boolean rowKeyOrderOptimizable = false;
        if (table.hasRowKeyOrderOptimizable()) {
            rowKeyOrderOptimizable = table.getRowKeyOrderOptimizable();
        }
        long updateCacheFrequency = 0;
        if (table.hasUpdateCacheFrequency()) {
            updateCacheFrequency = table.getUpdateCacheFrequency();
        }
        boolean isNamespaceMapped=false;
        if (table.hasIsNamespaceMapped()) {
            isNamespaceMapped = table.getIsNamespaceMapped();
        }
        String autoPartitionSeqName = null;
        if (table.hasAutoParititonSeqName()) {
            autoPartitionSeqName = table.getAutoParititonSeqName();
        }
        boolean isAppendOnlySchema = false;
        if (table.hasIsAppendOnlySchema()) {
            isAppendOnlySchema = table.getIsAppendOnlySchema();
        }
        // For backward compatibility. Clients older than 4.10 will always have non-encoded immutable tables.
        ImmutableStorageScheme storageScheme = ImmutableStorageScheme.ONE_CELL_PER_COLUMN;
        if (table.hasStorageScheme()) {
            storageScheme = ImmutableStorageScheme.fromSerializedValue(table.getStorageScheme().toByteArray()[0]);
        }
        // For backward compatibility. Clients older than 4.10 will always have non-encoded qualifiers.
        QualifierEncodingScheme qualifierEncodingScheme = QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
        if (table.hasEncodingScheme()) {
            qualifierEncodingScheme = QualifierEncodingScheme.fromSerializedValue(table.getEncodingScheme().toByteArray()[0]);
        }
        EncodedCQCounter encodedColumnQualifierCounter;
        if ((!EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) || tableType == PTableType.VIEW)) {
            encodedColumnQualifierCounter = PTable.EncodedCQCounter.NULL_COUNTER;
        }
        else {
            encodedColumnQualifierCounter = new EncodedCQCounter();
            if (table.getEncodedCQCountersList() != null) {
                for (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter cqCounterFromProto : table.getEncodedCQCountersList()) {
                    encodedColumnQualifierCounter.setValue(cqCounterFromProto.getColFamily(), cqCounterFromProto.getCounter());
                }
            }
        }
        Boolean useStatsForParallelization = null;
        if (table.hasUseStatsForParallelization()) {
            useStatsForParallelization = table.getUseStatsForParallelization();
        }

        // for older clients just use the value of the properties that are set on the view
        boolean viewModifiedUpdateCacheFrequency = true;
        boolean viewModifiedUseStatsForParallelization = true;
        if (table.hasViewModifiedUpdateCacheFrequency()) {
            viewModifiedUpdateCacheFrequency = table.getViewModifiedUpdateCacheFrequency();
        }
        if (table.hasViewModifiedUseStatsForParallelization()) {
            viewModifiedUseStatsForParallelization = table.getViewModifiedUseStatsForParallelization();
        }
        Long lastDDLTimestamp = null;
        if (table.hasLastDDLTimestamp()) {
            lastDDLTimestamp = table.getLastDDLTimestamp();
        }
        boolean isChangeDetectionEnabled = false;
        if (table.hasChangeDetectionEnabled()) {
            isChangeDetectionEnabled = table.getChangeDetectionEnabled();
        }
        String schemaVersion = null;
        if (table.hasSchemaVersion()) {
            schemaVersion = (String) PVarchar.INSTANCE.toObject(table.getSchemaVersion().toByteArray());
        }
        String externalSchemaId = null;
        if (table.hasExternalSchemaId()) {
            externalSchemaId =
                (String) PVarchar.INSTANCE.toObject(table.getExternalSchemaId().toByteArray());
        }
        String streamingTopicName = null;
        if (table.hasStreamingTopicName()) {
            streamingTopicName =
                (String) PVarchar.INSTANCE.toObject(table.getStreamingTopicName().toByteArray());
        }
        String indexWhere = null;
        if (table.hasIndexWhere()) {
            indexWhere =
                    (String) PVarchar.INSTANCE.toObject(table.getIndexWhere().toByteArray());
        }
        String cdcIncludeScopesStr = null;
        if (table.hasCDCIncludeScopes()) {
            cdcIncludeScopesStr = table.getCDCIncludeScopes();
        }

        TTLExpression ttl = TTL_EXPRESSION_NOT_DEFINED;
        if (table.hasTtl()) {
            String ttlExpr = (String) PVarchar.INSTANCE.toObject(table.getTtl().toByteArray());
            ttl = TTLExpressionFactory.create(ttlExpr);
        }

        byte[] rowKeyMatcher = null;
        if (table.hasRowKeyMatcher()) {
            rowKeyMatcher = table.getRowKeyMatcher().toByteArray();
        }

        try {
            return new PTableImpl.Builder()
                    .setType(tableType)
                    .setState(indexState)
                    .setTimeStamp(timeStamp)
                    .setIndexDisableTimestamp(indexDisableTimestamp)
                    .setSequenceNumber(sequenceNumber)
                    .setImmutableRows(isImmutableRows)
                    .setViewStatement(viewStatement)
                    .setDisableWAL(disableWAL)
                    .setMultiTenant(multiTenant)
                    .setStoreNulls(storeNulls)
                    .setViewType(viewType)
                    .setViewIndexIdType(viewIndexIdType)
                    .setViewIndexId(viewIndexId)
                    .setIndexType(indexType)
                    .setTransactionProvider(transactionProvider)
                    .setUpdateCacheFrequency(updateCacheFrequency)
                    .setNamespaceMapped(isNamespaceMapped)
                    .setAutoPartitionSeqName(autoPartitionSeqName)
                    .setAppendOnlySchema(isAppendOnlySchema)
                    // null check for backward compatibility and sanity. If any of the two below is null,
                    // then it means the table is a non-encoded table.
                    .setImmutableStorageScheme(storageScheme == null ?
                            ImmutableStorageScheme.ONE_CELL_PER_COLUMN : storageScheme)
                    .setQualifierEncodingScheme(qualifierEncodingScheme == null ?
                            QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : qualifierEncodingScheme)
                    .setBaseColumnCount(baseColumnCount)
                    .setEncodedCQCounter(encodedColumnQualifierCounter)
                    .setUseStatsForParallelization(useStatsForParallelization)
                    .setExcludedColumns(ImmutableList.of())
                    .setTenantId(tenantId)
                    .setSchemaName(schemaName)
                    .setTableName(tableName)
                    .setPhysicalTableName(physicalTableName)
                    .setPkName(pkName)
                    .setDefaultFamilyName(defaultFamilyName)
                    .setRowKeyOrderOptimizable(rowKeyOrderOptimizable)
                    .setBucketNum((bucketNum == NO_SALTING) ? null : bucketNum)
                    .setIndexes(indexes == null ? Collections.emptyList() : indexes)
                    .setTransformingNewTable(transformingNewTable)
                    .setParentSchemaName(parentSchemaName)
                    .setParentTableName(parentTableName)
                    .setBaseTableLogicalName(parentLogicalName)
                    .setPhysicalNames(physicalNames == null ?
                            ImmutableList.of() : ImmutableList.copyOf(physicalNames))
                    .setColumns(columns)
                    .setViewModifiedUpdateCacheFrequency(viewModifiedUpdateCacheFrequency)
                    .setViewModifiedUseStatsForParallelization(viewModifiedUseStatsForParallelization)
                    .setLastDDLTimestamp(lastDDLTimestamp)
                    .setIsChangeDetectionEnabled(isChangeDetectionEnabled)
                    .setSchemaVersion(schemaVersion)
                    .setExternalSchemaId(externalSchemaId)
                    .setStreamingTopicName(streamingTopicName)
                    .setCDCIncludeScopes(
                            CDCUtil.makeChangeScopeEnumsFromString(cdcIncludeScopesStr))
                    .setIndexWhere(indexWhere)
                    .setTTL(ttl)
                    .setRowKeyMatcher(rowKeyMatcher)
                    .build();
        } catch (SQLException e) {
            throw new RuntimeException(e); // Impossible
        }
    }