Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed 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 com.facebook.presto.connector.informationSchema;
 
 
 import java.util.List;
 import java.util.Map;
 
 import static com.facebook.presto.connector.informationSchema.InformationSchemaColumnHandle.toInformationSchemaColumnHandles;
 import static com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder;
 import static com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder;
 import static com.facebook.presto.metadata.MetadataUtil.findColumnMetadata;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static com.facebook.presto.util.Types.checkType;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Predicates.compose;
 import static com.google.common.base.Predicates.equalTo;
 import static com.google.common.collect.Iterables.filter;
 
         extends ReadOnlyConnectorMetadata
 {
     public static final String INFORMATION_SCHEMA = "information_schema";
 
     public static final SchemaTableName TABLE_COLUMNS = new SchemaTableName("columns");
     public static final SchemaTableName TABLE_TABLES = new SchemaTableName("tables");
     public static final SchemaTableName TABLE_VIEWS = new SchemaTableName("views");
     public static final SchemaTableName TABLE_SCHEMATA = new SchemaTableName("schemata");
     public static final SchemaTableName TABLE_INTERNAL_FUNCTIONS = new SchemaTableName("__internal_functions__");
     public static final SchemaTableName TABLE_INTERNAL_PARTITIONS = new SchemaTableName("__internal_partitions__");
 
     public static final Map<SchemaTableNameConnectorTableMetadataTABLES = schemaMetadataBuilder()
             .table(tableMetadataBuilder()
                     .column("table_catalog")
                     .column("table_schema")
                     .column("table_name")
                     .column("column_name")
                     .column("ordinal_position")
                     .column("column_default")
                     .column("is_nullable")
                     .column("data_type")
                     .column("is_partition_key")
                     .column("comment")
                     .build())
             .table(tableMetadataBuilder()
                     .column("table_catalog")
                     .column("table_schema")
                     .column("table_name")
                     .column("table_type")
                     .build())
             .table(tableMetadataBuilder()
                     .column("table_catalog")
                     .column("table_schema")
                     .column("table_name")
                     .column("view_definition")
                     .build())
             .table(tableMetadataBuilder()
                     .column("catalog_name")
                     .column("schema_name")
                     .build())
                     .column("function_name")
                     .column("argument_types")
                     .column("return_type")
                     .column("function_type")
                     .column("deterministic")
                     .column("description")
                     .build())
                     .column("table_catalog")
                     .column("table_schema")
                     .column("table_name")
                     .column("partition_number")
                    .column("partition_key")
                    .column("partition_value")
                    .build())
            .build();
    private final String catalogName;
    public InformationSchemaMetadata(String catalogName)
    {
        this. = catalogName;
    }
    {
        InformationSchemaTableHandle handle = checkType(tableHandleInformationSchemaTableHandle.class"tableHandle");
        checkArgument(handle.getCatalogName().equals(), "invalid table handle: expected catalog %s but got %s"handle.getCatalogName());
        checkArgument(.containsKey(handle.getSchemaTableName()), "table %s does not exist"handle.getSchemaTableName());
        return handle;
    }
    @Override
    public List<StringlistSchemaNames(ConnectorSession session)
    {
        return ImmutableList.of();
    }
    @Override
    public ConnectorTableHandle getTableHandle(ConnectorSession connectorSessionSchemaTableName tableName)
    {
        if (!.containsKey(tableName)) {
            return null;
        }
        Session session = Session.builder()
                .setUser(connectorSession.getUser())
                .setSource("information_schema")
                .setCatalog(""// default catalog is not be used
                .setSchema(""// default schema is not be used
                .setTimeZoneKey(connectorSession.getTimeZoneKey())
                .setLocale(connectorSession.getLocale())
                .setStartTime(connectorSession.getStartTime())
                .build();
        return new InformationSchemaTableHandle(sessiontableName.getSchemaName(), tableName.getTableName());
    }
    @Override
    {
        InformationSchemaTableHandle informationSchemaTableHandle = checkTableHandle(tableHandle);
        return .get(informationSchemaTableHandle.getSchemaTableName());
    }
    @Override
    public List<SchemaTableNamelistTables(ConnectorSession sessionString schemaNameOrNull)
    {
        if (schemaNameOrNull == null) {
            return ImmutableList.copyOf(.keySet());
        }
        return ImmutableList.copyOf(filter(.keySet(), compose(equalTo(schemaNameOrNull), SchemaTableName::getSchemaName)));
    }
    @Override
    {
        return null;
    }
    @Override
    public ColumnMetadata getColumnMetadata(ConnectorTableHandle tableHandleConnectorColumnHandle columnHandle)
    {
        InformationSchemaTableHandle informationSchemaTableHandle = checkTableHandle(tableHandle);
        ConnectorTableMetadata tableMetadata = .get(informationSchemaTableHandle.getSchemaTableName());
        String columnName = checkType(columnHandleInformationSchemaColumnHandle.class"columnHandle").getColumnName();
        ColumnMetadata columnMetadata = findColumnMetadata(tableMetadatacolumnName);
        checkArgument(columnMetadata != null"Column %s on table %s does not exist"columnNametableMetadata.getTable());
        return columnMetadata;
    }
    @Override
    {
        InformationSchemaTableHandle informationSchemaTableHandle = checkTableHandle(tableHandle);
        ConnectorTableMetadata tableMetadata = .get(informationSchemaTableHandle.getSchemaTableName());
        return toInformationSchemaColumnHandles(tableMetadata);
    }
    @Override
    {
        checkNotNull(prefix"prefix is null");
        ImmutableMap.Builder<SchemaTableNameList<ColumnMetadata>> builder = ImmutableMap.builder();
        for (Entry<SchemaTableNameConnectorTableMetadataentry : .entrySet()) {
            if (prefix.matches(entry.getKey())) {
                builder.put(entry.getKey(), entry.getValue().getColumns());
            }
        }
        return builder.build();
    }
    {
        checkArgument(.containsKey(tableName), "table does not exist: %s"tableName);
        return .get(tableName).getColumns();
    }
New to GrepCode? Check out our FAQ X