15 package com.cloudera.impala.catalog;
17 import java.util.List;
20 import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
21 import org.apache.hadoop.hive.metastore.api.FieldSchema;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.cloudera.impala.extdatasource.v1.ExternalDataSource;
26 import com.cloudera.impala.thrift.TCatalogObjectType;
27 import com.cloudera.impala.thrift.TColumn;
28 import com.cloudera.impala.thrift.TDataSource;
29 import com.cloudera.impala.thrift.TDataSourceTable;
30 import com.cloudera.impala.thrift.TResultSet;
31 import com.cloudera.impala.thrift.TResultSetMetadata;
32 import com.cloudera.impala.thrift.TTable;
33 import com.cloudera.impala.thrift.TTableDescriptor;
34 import com.cloudera.impala.thrift.TTableType;
36 import com.google.common.base.Preconditions;
47 private final static Logger
LOG = LoggerFactory.getLogger(DataSourceTable.class);
78 TableId id, org.apache.hadoop.hive.metastore.api.Table msTable,
79 Db db, String
name, String owner) {
80 super(
id, msTable, db, name, owner);
103 Preconditions.checkNotNull(colType);
111 Preconditions.checkNotNull(primitiveType);
112 switch (primitiveType) {
140 private void loadColumns(List<FieldSchema> fieldSchemas, HiveMetaStoreClient client)
143 for (FieldSchema s: fieldSchemas) {
153 super.loadFromThrift(thriftTable);
154 TDataSourceTable dataSourceTable = thriftTable.getData_source_table();
160 public void load(
Table oldValue, HiveMetaStoreClient client,
162 Preconditions.checkNotNull(msTbl);
163 LOG.debug(
"load table: " + db_.getName() +
"." +
name_);
169 dataSource_ =
new TDataSource(dataSourceName, location, className, apiVersionString);
172 if (msTbl.getPartitionKeysSize() > 0) {
173 throw new TableLoadingException(
"Data source table cannot contain clustering " +
174 "columns: " +
name_);
185 }
catch (Exception e) {
186 throw new TableLoadingException(
"Failed to load metadata for data source table: " +
192 org.apache.hadoop.hive.metastore.api.Table msTbl, String key, String dataSourceName)
194 String val = msTbl.getParameters().
get(key);
197 "by external data source %s. Missing required metadata: %s",
name_,
198 dataSourceName == null ?
"<unknown>" : dataSourceName, key));
209 TResultSet result =
new TResultSet();
210 TResultSetMetadata resultSchema =
new TResultSetMetadata();
212 result.setSchema(resultSchema);
215 result.addToRows(rowBuilder.get());
221 TTableDescriptor tableDesc =
new TTableDescriptor(
id_.asInt(),
234 TTable table = super.toThrift();
235 table.setTable_type(TTableType.DATA_SOURCE_TABLE);
253 org.apache.hadoop.hive.metastore.api.Table msTbl) {
List< String > getColumnNames()
static long getRowCount(Map< String, String > parameters)
static final ScalarType BIGINT
static boolean isSupportedPrimitiveType(PrimitiveType primitiveType)
static final String TBL_PROP_API_VER
static boolean isSupportedColumnType(Type colType)
static final String TBL_PROP_DATA_SRC_NAME
void addColumn(Column col)
TDataSource getDataSource()
PrimitiveType getPrimitiveType()
TDataSourceTable getDataSourceTable()
DataSourceTable(TableId id, org.apache.hadoop.hive.metastore.api.Table msTable, Db db, String name, String owner)
static boolean isDataSourceTable(org.apache.hadoop.hive.metastore.api.Table msTbl)
TResultSet getTableStats()
void loadFromThrift(TTable thriftTable)
Type parseColumnType(FieldSchema fs)
TCatalogObjectType getCatalogObjectType()
ArrayList< Column > getColumns()
void loadColumns(List< FieldSchema > fieldSchemas, HiveMetaStoreClient client)
static final String TBL_PROP_LOCATION
String getRequiredTableProperty(org.apache.hadoop.hive.metastore.api.Table msTbl, String key, String dataSourceName)
void load(Table oldValue, HiveMetaStoreClient client, org.apache.hadoop.hive.metastore.api.Table msTbl)
static final String TBL_PROP_CLASS
org.apache.hadoop.hive.metastore.api.Table getMetaStoreTable()
void toThrift(TColumnType container)
Table(TableId id, org.apache.hadoop.hive.metastore.api.Table msTable, Db db, String name, String owner)
TTableDescriptor toThriftDescriptor(Set< Long > referencedPartitions)
static final String TBL_PROP_INIT_STRING