Load table meta data.

@param logicTableName logic table name
@param shardingRule sharding rule
@return table meta data
329799
@SneakyThrows
    public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) {
        return tableMetaDataLoader.load(logicTableName, shardingRule);
    }
335081
public static AbstractUpdateParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
        switch (dbType) {
            case H2:
            case MySQL:
                return new MySQLUpdateParser(shardingRule, lexerEngine);
            case Oracle:
                return new OracleUpdateParser(shardingRule, lexerEngine);
            case SQLServer:
                return new SQLServerUpdateParser(shardingRule, lexerEngine);
            case PostgreSQL:
                return new PostgreSQLUpdateParser(shardingRule, lexerEngine);
            default:
                throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
        }
    }
358019
public String getRawMasterDataSourceName(final String dataSourceName) {
        for (MasterSlaveRuleConfiguration each : shardingRuleConfig.getMasterSlaveRuleConfigs()) {
            if (each.getName().equals(dataSourceName)) {
                return each.getMasterDataSourceName();
            }
        }
        return dataSourceName;
    }
1005740
public ShardingStrategy getDatabaseShardingStrategy(final TableRule tableRule) {
        return null == tableRule.getDatabaseShardingStrategy() ? defaultDatabaseShardingStrategy : tableRule.getDatabaseShardingStrategy();
    }
1026614
private Map<String, Integer> getShardNumbers(String tableName, Set<String> targObjIDs) {
        TableDefinition tableDef = m_tableDef.getAppDef().getTableDef(tableName);
        FieldDefinition shardField = tableDef.getShardingField();
        Map<String, String> shardFieldMap =
           SpiderService.instance().getObjectScalar(tableDef, targObjIDs, shardField.getName());
        Map<String, Integer> shardNoMap = new HashMap<>();
        for (String objID : shardFieldMap.keySet()) {
            Date shardingFieldDate = Utils.dateFromString(shardFieldMap.get(objID));
            int shardNo = tableDef.computeShardNumber(shardingFieldDate);
            shardNoMap.put(objID, shardNo);
        }
        return shardNoMap;
    }
777221
public Optional<String> getAssistedQueryColumn(final String logicTableName, final String columnName) {
        if (assistedQueryColumns.isEmpty()) {
            return Optional.absent();
        }
        for (ColumnNode each : columns) {
            ColumnNode target = new ColumnNode(logicTableName, columnName);
            if (each.equals(target)) {
                return Optional.of(assistedQueryColumns.get(columns.indexOf(target)).getColumnName());
            }
        }
        return Optional.absent();
    }
378119
public TableMetadata fetchTableMetadata() {

        Metadata metadata = getSession().getCluster().getMetadata();
        KeyspaceMetadata ksMetadata = metadata.getKeyspace(quote(this.catalog));

        if (ksMetadata != null) {
            return ksMetadata.getTable(quote(this.table));
        } else {
            return null;
        }
    }
1021886
private void validateTableOptionShardingStart(TableDefinition tableDef, String optValue) {
        Utils.require(isValidShardDate(optValue),
                      "'sharding-start' must be YYYY-MM-DD: " + optValue);
        GregorianCalendar shardingStartDate = new GregorianCalendar(Utils.UTC_TIMEZONE);
        shardingStartDate.setTime(Utils.dateFromString(optValue));

        // 'sharding-start' requires 'sharding-field'
        Utils.require(tableDef.getOption(CommonDefs.OPT_SHARDING_FIELD) != null,
                      "Option 'sharding-start' requires option 'sharding-field'");
    }
863276
private void validateTableOptionShardingField(TableDefinition tableDef, String optValue) {
        // Verify that the sharding-field exists and is a timestamp field.
        FieldDefinition shardingFieldDef = tableDef.getFieldDef(optValue);
        Utils.require(shardingFieldDef != null,
                      "Sharding field has not been defined: " + optValue);
        assert shardingFieldDef != null;    // Make FindBugs happy
        Utils.require(shardingFieldDef.getType() == FieldType.TIMESTAMP,
                      "Sharding field must be a timestamp field: " + optValue);
        Utils.require(!shardingFieldDef.isCollection(),
                        "Sharding field cannot be a collection: " + optValue);
        
        // Default sharding-granularity to MONTH.
        if (tableDef.getOption(CommonDefs.OPT_SHARDING_GRANULARITY) == null) {
            tableDef.setOption(CommonDefs.OPT_SHARDING_GRANULARITY, "MONTH");
        }
        
        // Default sharding-start to "tomorrow".
        if (tableDef.getOption(CommonDefs.OPT_SHARDING_START) == null) {
            GregorianCalendar startDate = new GregorianCalendar(Utils.UTC_TIMEZONE);
            startDate.add(Calendar.DAY_OF_MONTH, 1);  // adds 1 day
            String startOpt = String.format("%04d-%02d-%02d",
                                            startDate.get(Calendar.YEAR),
                                            startDate.get(Calendar.MONTH)+1,    // 0-relative!
                                            startDate.get(Calendar.DAY_OF_MONTH));
            tableDef.setOption(CommonDefs.OPT_SHARDING_START, startOpt);
        }
    }
467009
public void optimize(final SQLStatementRule rule, final SQLStatement sqlStatement) {
        Optional<SQLStatementOptimizer> optimizer = rule.getOptimizer();
        if (optimizer.isPresent()) {
            optimizer.get().optimize(sqlStatement, shardingTableMetaData);
        }
    }
1163132
public RuleMetadata getMetaData(String attributeName) {

        if (metadataList != null && attributeName != null) {
            for (int i = 0; i < metadataList.length; i++) {
                if (attributeName.equals(metadataList[i].getAttributeName())) {
                    return metadataList[i];
                }
            }
        }
        return null;
    }
629223
private Document getTableMetadata(SchemaTableName schemaTableName)
            throws TableNotFoundException
    {
        String schemaName = schemaTableName.getSchemaName();
        String tableName = schemaTableName.getTableName();

        MongoDatabase db = client.getDatabase(schemaName);
        MongoCollection<Document> schema = db.getCollection(schemaCollection);

        Document doc = schema
                .find(new Document(TABLE_NAME_KEY, tableName)).first();

        if (doc == null) {
            if (!collectionExists(db, tableName)) {
                throw new TableNotFoundException(schemaTableName);
            }
            else {
                Document metadata = new Document(TABLE_NAME_KEY, tableName);
                metadata.append(FIELDS_KEY, guessTableFields(schemaTableName));

                schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
                schema.insertOne(metadata);

                return metadata;
            }
        }

        return doc;
    }
417680
private Metadata createMetadata(String tableName) {
    Metadata metadata = new Metadata();
    if (tableName != null) {
      metadata.put(GRPC_RESOURCE_PREFIX_KEY, tableName);
    }
    return metadata;
  }
33609
public Integer getAssistedQueryColumnCount(final String logicTableName) {
        for (ShardingEncryptorStrategy each : shardingEncryptorStrategies.values()) {
            int result = each.getAssistedQueryColumnCount(logicTableName);
            if (result > 0) {
                return result;
            }
        }
        return 0;
    }
579233
public SQLRouteResult route(final String logicSQL) {
        SQLStatement sqlStatement = shardingRouter.parse(logicSQL, false);
        return masterSlaveRouter.route(shardingRouter.route(logicSQL, Collections.emptyList(), sqlStatement));
    }
1106332
def _load(self, **kwargs):
        """"""

        if self._check_existence_by_collection(
                self._meta_data['container'], kwargs['name']):
            return super(Rules, self)._load(**kwargs)
        msg = 'The rule named, {}, does not exist on the device.'.format(
            kwargs['name'])
        raise NonExtantPolicyRule(msg)
1097928
public static SQLParser newInstance(
            final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine, final ShardingTableMetaData shardingTableMetaData, final String sql) {
        lexerEngine.nextToken();
        TokenType tokenType = lexerEngine.getCurrentToken().getType();
        if (DQLStatement.isDQL(tokenType)) {
            if (DatabaseType.MySQL == dbType || DatabaseType.H2 == dbType) {
                return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
            }
            return getDQLParser(dbType, shardingRule, lexerEngine, shardingTableMetaData);
        }
        if (DMLStatement.isDML(tokenType)) {
            if (DatabaseType.MySQL == dbType || DatabaseType.H2 == dbType) {
                return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
            }
            return getDMLParser(dbType, tokenType, shardingRule, lexerEngine, shardingTableMetaData);
        }
        if (MySQLKeyword.REPLACE == tokenType) {
            if (DatabaseType.MySQL == dbType || DatabaseType.H2 == dbType) {
                return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
            }
        }
        if (TCLStatement.isTCL(tokenType)) {
            return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
        }
        if (DALStatement.isDAL(tokenType)) {
            if (DatabaseType.PostgreSQL == dbType && PostgreSQLKeyword.SHOW == tokenType) {
                return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
            }
            return getDALParser(dbType, (Keyword) tokenType, shardingRule, lexerEngine);
        }
        lexerEngine.nextToken();
        TokenType secondaryTokenType = lexerEngine.getCurrentToken().getType();
        if (DCLStatement.isDCL(tokenType, secondaryTokenType)) {
            return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
        }
        if (DDLStatement.isDDL(tokenType, secondaryTokenType)) {
            return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
        }
        if (TCLStatement.isTCLUnsafe(dbType, tokenType, lexerEngine)) {
            return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData);
        }
        if (DefaultKeyword.SET.equals(tokenType)) {
            return SetParserFactory.newInstance();
        }
        throw new SQLParsingUnsupportedException(tokenType);
    }