public TableSpec()

in flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserBaseSemanticAnalyzer.java [2129:2240]


        public TableSpec(
                CatalogRegistry catalogRegistry,
                HiveConf conf,
                HiveParserASTNode ast,
                FrameworkConfig frameworkConfig,
                RelOptCluster cluster)
                throws SemanticException {
            assert (ast.getToken().getType() == HiveASTParser.TOK_TAB
                    || ast.getToken().getType() == HiveASTParser.TOK_TABLE_PARTITION
                    || ast.getToken().getType() == HiveASTParser.TOK_TABTYPE
                    || ast.getToken().getType() == HiveASTParser.TOK_CREATETABLE
                    || ast.getToken().getType() == HiveASTParser.TOK_CREATE_MATERIALIZED_VIEW);
            int childIndex = 0;
            numDynParts = 0;

            // get table metadata
            tableIdentifier =
                    getObjectIdentifier(catalogRegistry, (HiveParserASTNode) ast.getChild(0));
            if (ast.getToken().getType() != HiveASTParser.TOK_CREATETABLE
                    && ast.getToken().getType() != HiveASTParser.TOK_CREATE_MATERIALIZED_VIEW) {
                table = getResolvedCatalogBaseTable(catalogRegistry, tableIdentifier);
            }

            // get partition metadata if partition specified
            if (ast.getChildCount() == 2
                    && ast.getToken().getType() != HiveASTParser.TOK_CREATETABLE
                    && ast.getToken().getType() != HiveASTParser.TOK_CREATE_MATERIALIZED_VIEW) {
                childIndex = 1;
                HiveParserASTNode partspec = (HiveParserASTNode) ast.getChild(1);
                // partSpec is a mapping from partition column name to its value.
                Map<String, String> tmpPartSpec =
                        CollectionUtil.newHashMapWithExpectedSize(partspec.getChildCount());
                for (int i = 0; i < partspec.getChildCount(); ++i) {
                    HiveParserASTNode partspecVal = (HiveParserASTNode) partspec.getChild(i);
                    String val = null;
                    String colName =
                            unescapeIdentifier(partspecVal.getChild(0).getText().toLowerCase());
                    if (partspecVal.getChildCount() < 2) { // DP in the form of T partition (ds, hr)
                        ++numDynParts;
                    } else { // in the form of T partition (ds="2010-03-03")
                        val = stripQuotes(partspecVal.getChild(1).getText());
                    }
                    tmpPartSpec.put(colName, val);
                }

                if (!(table instanceof CatalogTable)) {
                    throw new IllegalArgumentException(
                            tableIdentifier.asSummaryString()
                                    + " is not a table, partition is only allowed for table.");
                }

                // check if the columns value type in the partition() clause are valid
                validatePartColumnType(
                        (ResolvedCatalogTable) table,
                        tmpPartSpec,
                        ast,
                        conf,
                        frameworkConfig,
                        cluster);

                List<String> parts = ((CatalogTable) table).getPartitionKeys();
                partSpec =
                        CollectionUtil.newLinkedHashMapWithExpectedSize(partspec.getChildCount());
                for (String part : parts) {
                    partSpec.put(part, tmpPartSpec.get(part));
                }

                // check if the partition spec is valid
                if (numDynParts > 0) {
                    int numStaPart = parts.size() - numDynParts;
                    if (numStaPart == 0
                            && conf.getVar(HiveConf.ConfVars.DYNAMICPARTITIONINGMODE)
                                    .equalsIgnoreCase("strict")) {
                        throw new SemanticException(
                                ErrorMsg.DYNAMIC_PARTITION_STRICT_MODE.getMsg());
                    }

                    // check the partitions in partSpec be the same as defined in table schema
                    if (partSpec.keySet().size() != parts.size()) {
                        errorPartSpec(partSpec, parts);
                    }
                    Iterator<String> itrPsKeys = partSpec.keySet().iterator();
                    for (String part : parts) {
                        if (!itrPsKeys.next().equalsIgnoreCase(part)) {
                            errorPartSpec(partSpec, parts);
                        }
                    }

                    // check if static partition appear after dynamic partitions
                    for (String part : parts) {
                        if (partSpec.get(part.toLowerCase()) == null) {
                            if (numStaPart > 0) { // found a DP, but there exists ST as subpartition
                                throw new SemanticException(
                                        HiveParserErrorMsg.getMsg(
                                                ErrorMsg.PARTITION_DYN_STA_ORDER,
                                                ast.getChild(childIndex)));
                            }
                            break;
                        } else {
                            --numStaPart;
                        }
                    }
                    partHandle = null;
                    specType = TableSpec.SpecType.DYNAMIC_PARTITION;
                } else {
                    partHandle = new CatalogPartitionSpec(partSpec);
                    specType = TableSpec.SpecType.STATIC_PARTITION;
                }
            } else {
                specType = TableSpec.SpecType.TABLE_ONLY;
            }
        }