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.metadata;
 
 
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.util.Locale.ENGLISH;
 
 public final class MetadataUtil
 {
     private MetadataUtil() {}
 
     public static void checkTableName(String catalogNameOptional<StringschemaNameOptional<StringtableName)
     {
         checkCatalogName(catalogName);
         checkSchemaName(schemaName);
         checkTableName(tableName);
 
         checkArgument(schemaName.isPresent() || !tableName.isPresent(), "tableName specified but schemaName is missing");
     }
 
     public static String checkCatalogName(String catalogName)
     {
         return checkLowerCase(catalogName"catalogName");
     }
 
     public static String checkSchemaName(String schemaName)
     {
         return checkLowerCase(schemaName"schemaName");
     }
 
     public static Optional<StringcheckSchemaName(Optional<StringschemaName)
     {
         return checkLowerCase(schemaName"schemaName");
     }
 
     public static String checkTableName(String tableName)
     {
         return checkLowerCase(tableName"tableName");
     }
 
     public static Optional<StringcheckTableName(Optional<StringtableName)
     {
         return checkLowerCase(tableName"tableName");
     }
 
     public static String checkColumnName(String catalogName)
     {
         return checkLowerCase(catalogName"catalogName");
     }
 
     public static void checkTableName(String catalogNameString schemaNameString tableName)
     {
         checkLowerCase(catalogName"catalogName");
         checkLowerCase(schemaName"schemaName");
         checkLowerCase(tableName"tableName");
     }
 
     public static Optional<StringcheckLowerCase(Optional<StringvalueString name)
     {
         if (value.isPresent()) {
             checkLowerCase(value.get(), name);
         }
         return value;
     }
 
     public static String checkLowerCase(String valueString name)
     {
         checkNotNull(value"%s is null"name);
         checkArgument(value.equals(value.toLowerCase()), "%s is not lowercase"name);
         return value;
     }
 
     public static ColumnMetadata findColumnMetadata(ConnectorTableMetadata tableMetadataString columnName)
     {
        for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
            if (columnName.equals(columnMetadata.getName())) {
                return columnMetadata;
            }
        }
        return null;
    }
    public static QualifiedTableName createQualifiedTableName(Session sessionQualifiedName name)
    {
        checkNotNull(session"session is null");
        checkNotNull(name"name is null");
        checkArgument(name.getParts().size() <= 3, "Too many dots in table name: %s"name);
        List<Stringparts = Lists.reverse(name.getParts());
        String tableName = parts.get(0);
        String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema();
        String catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog();
        return new QualifiedTableName(catalogNameschemaNametableName);
    }
    public static class SchemaMetadataBuilder
    {
        public static SchemaMetadataBuilder schemaMetadataBuilder()
        {
            return new SchemaMetadataBuilder();
        }
        private final ImmutableMap.Builder<SchemaTableNameConnectorTableMetadatatables = ImmutableMap.builder();
        public SchemaMetadataBuilder table(ConnectorTableMetadata tableMetadata)
        {
            .put(tableMetadata.getTable(), tableMetadata);
            return this;
        }
        {
            return .build();
        }
    }
    public static class TableMetadataBuilder
    {
        public static TableMetadataBuilder tableMetadataBuilder(String schemaNameString tableName)
        {
            return new TableMetadataBuilder(new SchemaTableName(schemaNametableName));
        }
        public static TableMetadataBuilder tableMetadataBuilder(SchemaTableName tableName)
        {
            return new TableMetadataBuilder(tableName);
        }
        private final SchemaTableName tableName;
        private final ImmutableList.Builder<ColumnMetadatacolumns = ImmutableList.builder();
        private int ordinalPosition;
        private TableMetadataBuilder(SchemaTableName tableName)
        {
            this. = tableName;
        }
        public TableMetadataBuilder column(String columnNameType type)
        {
            .add(new ColumnMetadata(columnNametypefalse));
            ++;
            return this;
        }
        public TableMetadataBuilder partitionKeyColumn(String columnNameType type)
        {
            .add(new ColumnMetadata(columnNametypetrue));
            ++;
            return this;
        }
        public ConnectorTableMetadata build()
        {
            return new ConnectorTableMetadata(.build());
        }
    }
New to GrepCode? Check out our FAQ X