public class MetaStoreUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ARCHIVING_LEVEL |
static String |
DATABASE_WAREHOUSE_SUFFIX |
static String |
DEFAULT_DATABASE_COMMENT |
static String |
DEFAULT_DATABASE_NAME |
protected static org.apache.commons.logging.Log |
LOG |
Constructor and Description |
---|
MetaStoreUtils() |
Modifier and Type | Method and Description |
---|---|
static ClassLoader |
addToClassPath(ClassLoader cloader,
String[] newPaths)
Add new elements to the classpath.
|
static boolean |
canDropPartition(Table table,
Partition partition) |
static boolean |
compareFieldColumns(List<FieldSchema> schema1,
List<FieldSchema> schema2) |
static boolean |
containsAllFastStats(Map<String,String> partParams) |
static Table |
createColumnsetSchema(String name,
List<String> columns,
List<String> partCols,
org.apache.hadoop.conf.Configuration conf) |
static void |
deleteWHDirectory(org.apache.hadoop.fs.Path path,
org.apache.hadoop.conf.Configuration conf,
boolean use_trash) |
static int |
findFreePort()
Finds a free port on the machine.
|
static int |
getArchivingLevel(Partition part) |
static Class<?> |
getClass(String rawStoreClassName) |
static String |
getColumnCommentsFromFieldSchema(List<FieldSchema> fieldSchemas) |
static String |
getColumnNamesFromFieldSchema(List<FieldSchema> fieldSchemas)
Convert FieldSchemas to columnNames.
|
static String |
getColumnTypesFromFieldSchema(List<FieldSchema> fieldSchemas)
Convert FieldSchemas to columnTypes.
|
static String |
getDDLFromFieldSchema(String structName,
List<FieldSchema> fieldSchemas)
Convert FieldSchemas to Thrift DDL.
|
static Deserializer |
getDeserializer(org.apache.hadoop.conf.Configuration conf,
Partition part,
Table table)
getDeserializer
Get the Deserializer for a partition.
|
static Deserializer |
getDeserializer(org.apache.hadoop.conf.Configuration conf,
Table table,
boolean skipConfError)
getDeserializer
Get the Deserializer for a table.
|
static Class<? extends Deserializer> |
getDeserializerClass(org.apache.hadoop.conf.Configuration conf,
Table table) |
static FieldSchema |
getFieldSchemaFromTypeInfo(String fieldName,
TypeInfo typeInfo)
Convert TypeInfo to FieldSchema.
|
static List<FieldSchema> |
getFieldsFromDeserializer(String tableName,
Deserializer deserializer) |
static String |
getFullDDLFromFieldSchema(String structName,
List<FieldSchema> fieldSchemas)
Convert FieldSchemas to Thrift DDL + column names and column types
|
static String |
getIndexTableName(String dbName,
String baseTblName,
String indexName) |
static String |
getListType(String t) |
static String |
getMapType(String k,
String v) |
static Map<String,String> |
getMetaStoreSaslProperties(HiveConf conf)
Read and return the meta store Sasl configuration.
|
static org.apache.hadoop.fs.Path |
getOriginalLocation(Partition part) |
static Properties |
getPartitionMetadata(Partition partition,
Table table) |
static Properties |
getPartSchemaFromTableSchema(StorageDescriptor sd,
StorageDescriptor tblsd,
Map<String,String> parameters,
String databaseName,
String tableName,
List<FieldSchema> partitionKeys,
Properties tblSchema)
Get partition level schema from table level schema.
|
static ProtectMode |
getProtectMode(Partition partition) |
static ProtectMode |
getProtectMode(Table table) |
static List<String> |
getPvals(List<FieldSchema> partCols,
Map<String,String> partSpec)
Given a list of partition columns and a partial mapping from
some partition columns to values the function returns the values
for the column.
|
static String[] |
getQualifiedName(String defaultDbName,
String tableName) |
static Properties |
getSchema(Partition part,
Table table) |
static Properties |
getSchema(StorageDescriptor sd,
StorageDescriptor tblsd,
Map<String,String> parameters,
String databaseName,
String tableName,
List<FieldSchema> partitionKeys) |
static Properties |
getTableMetadata(Table table) |
static boolean |
isArchived(Partition part) |
static boolean |
isDirEmpty(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Utility method that determines if a specified directory already has
contents (non-hidden files) or not - useful to determine if an
immutable table already has contents, for example.
|
static boolean |
isExternalTable(Table table)
Determines whether a table is an external table.
|
static boolean |
isImmutableTable(Table table)
Determines whether a table is an immutable table.
|
static boolean |
isIndexTable(Table table) |
static boolean |
isNonNativeTable(Table table) |
static boolean |
isView(Table table) |
static void |
makeDir(org.apache.hadoop.fs.Path path,
HiveConf hiveConf) |
static String |
makeFilterStringFromMap(Map<String,String> m)
Given a map of partition column names to values, this creates a filter
string that can be used to call the *byFilter methods
|
static <T> T |
newInstance(Class<T> theClass,
Class<?>[] parameterTypes,
Object[] initargs)
Create an object of the given class.
|
static boolean |
partitionNameHasValidCharacters(List<String> partVals,
Pattern partitionValidationPattern) |
static void |
populateQuickStats(org.apache.hadoop.fs.FileStatus[] fileStatus,
Map<String,String> params) |
static boolean |
pvalMatches(List<String> partial,
List<String> full)
Returns true if partial has the same values as full for all values that
aren't empty in partial.
|
static void |
recursiveDelete(File f)
recursiveDelete
just recursively deletes a dir - you'd think Java would have something to
do this??
|
static boolean |
requireCalStats(org.apache.hadoop.conf.Configuration hiveConf,
Partition oldPart,
Partition newPart,
Table tbl) |
static void |
setSerdeParam(SerDeInfo sdi,
Properties schema,
String param) |
static void |
startMetaStore(int port,
HadoopThriftAuthBridge bridge) |
static void |
startMetaStore(int port,
HadoopThriftAuthBridge bridge,
HiveConf hiveConf) |
static Map<String,String> |
trimMapNulls(Map<String,String> dnMap,
boolean retrieveMapNullsAsEmptyStrings)
We have aneed to sanity-check the map before conversion from persisted objects to
metadata thrift objects because null values in maps will cause a NPE if we send
across thrift.
|
static String |
typeToThriftType(String type)
Convert type to ThriftType.
|
static boolean |
updatePartitionStatsFast(PartitionSpecProxy.PartitionIterator part,
Warehouse wh,
boolean madeDir,
boolean forceRecompute)
Updates the numFiles and totalSize parameters for the passed Partition by querying
the warehouse if the passed Partition does not already have values for these parameters.
|
static boolean |
updatePartitionStatsFast(Partition part,
Warehouse wh) |
static boolean |
updatePartitionStatsFast(Partition part,
Warehouse wh,
boolean madeDir) |
static boolean |
updatePartitionStatsFast(Partition part,
Warehouse wh,
boolean madeDir,
boolean forceRecompute)
Updates the numFiles and totalSize parameters for the passed Partition by querying
the warehouse if the passed Partition does not already have values for these parameters.
|
static boolean |
updateUnpartitionedTableStatsFast(Database db,
Table tbl,
Warehouse wh,
boolean madeDir) |
static boolean |
updateUnpartitionedTableStatsFast(Database db,
Table tbl,
Warehouse wh,
boolean madeDir,
boolean forceRecompute) |
static boolean |
updateUnpartitionedTableStatsFast(Table tbl,
org.apache.hadoop.fs.FileStatus[] fileStatus,
boolean newDir,
boolean forceRecompute)
Updates the numFiles and totalSize parameters for the passed unpartitioned Table by querying
the warehouse if the passed Table does not already have values for these parameters.
|
static boolean |
validateColumnName(String name) |
static boolean |
validateColumnType(String type)
validate column type
if it is predefined, yes.
|
static boolean |
validateName(String name)
validateName
Checks the name conforms to our standars which are: "[a-zA-z_0-9]+".
|
static void |
validatePartitionNameCharacters(List<String> partVals,
Pattern partitionValidationPattern) |
static String |
validateSkewedColNames(List<String> cols) |
static String |
validateSkewedColNamesSubsetCol(List<String> skewedColNames,
List<FieldSchema> cols) |
static String |
validateTblColumns(List<FieldSchema> cols) |
protected static final org.apache.commons.logging.Log LOG
public static final String DEFAULT_DATABASE_NAME
public static final String DEFAULT_DATABASE_COMMENT
public static final String DATABASE_WAREHOUSE_SUFFIX
public static String ARCHIVING_LEVEL
public static Table createColumnsetSchema(String name, List<String> columns, List<String> partCols, org.apache.hadoop.conf.Configuration conf) throws MetaException
MetaException
public static void recursiveDelete(File f) throws IOException
f
- - the file/dir to deleteIOException
- propogate f.delete() exceptionspublic static boolean containsAllFastStats(Map<String,String> partParams)
partParams
- public static boolean updateUnpartitionedTableStatsFast(Database db, Table tbl, Warehouse wh, boolean madeDir) throws MetaException
MetaException
public static boolean updateUnpartitionedTableStatsFast(Database db, Table tbl, Warehouse wh, boolean madeDir, boolean forceRecompute) throws MetaException
MetaException
public static boolean updateUnpartitionedTableStatsFast(Table tbl, org.apache.hadoop.fs.FileStatus[] fileStatus, boolean newDir, boolean forceRecompute) throws MetaException
tbl
- fileStatus
- newDir
- if true, the directory was just created and can be assumed to be emptyforceRecompute
- Recompute stats even if the passed Table already has
these parameters setMetaException
public static void populateQuickStats(org.apache.hadoop.fs.FileStatus[] fileStatus, Map<String,String> params)
public static boolean requireCalStats(org.apache.hadoop.conf.Configuration hiveConf, Partition oldPart, Partition newPart, Table tbl)
public static boolean updatePartitionStatsFast(Partition part, Warehouse wh) throws MetaException
MetaException
public static boolean updatePartitionStatsFast(Partition part, Warehouse wh, boolean madeDir) throws MetaException
MetaException
public static boolean updatePartitionStatsFast(Partition part, Warehouse wh, boolean madeDir, boolean forceRecompute) throws MetaException
part
- wh
- madeDir
- if true, the directory was just created and can be assumed to be emptyforceRecompute
- Recompute stats even if the passed Partition already has
these parameters setMetaException
public static boolean updatePartitionStatsFast(PartitionSpecProxy.PartitionIterator part, Warehouse wh, boolean madeDir, boolean forceRecompute) throws MetaException
part
- wh
- madeDir
- if true, the directory was just created and can be assumed to be emptyforceRecompute
- Recompute stats even if the passed Partition already has
these parameters setMetaException
public static Deserializer getDeserializer(org.apache.hadoop.conf.Configuration conf, Table table, boolean skipConfError) throws MetaException
conf
- - hadoop configtable
- the tableMetaException
- if any problems instantiating the Deserializer
todo - this should move somewhere into serde.jarpublic static Class<? extends Deserializer> getDeserializerClass(org.apache.hadoop.conf.Configuration conf, Table table) throws Exception
Exception
public static Deserializer getDeserializer(org.apache.hadoop.conf.Configuration conf, Partition part, Table table) throws MetaException
conf
- - hadoop configpart
- the partitiontable
- the tableMetaException
- if any problems instantiating the Deserializerpublic static void deleteWHDirectory(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf, boolean use_trash) throws MetaException
MetaException
public static List<String> getPvals(List<FieldSchema> partCols, Map<String,String> partSpec)
partCols
- the list of table partition columnspartSpec
- the partial mapping from partition column to valuespublic static boolean validateName(String name)
name
- the name to validateMetaException
- if it doesn't match the pattern.public static final boolean validateColumnName(String name)
public static String validateTblColumns(List<FieldSchema> cols)
public static boolean validateColumnType(String type)
name
- public static String validateSkewedColNamesSubsetCol(List<String> skewedColNames, List<FieldSchema> cols)
public static void setSerdeParam(SerDeInfo sdi, Properties schema, String param)
public static String typeToThriftType(String type)
public static String getFullDDLFromFieldSchema(String structName, List<FieldSchema> fieldSchemas)
structName
- The name of the tablefieldSchemas
- List of fields along with their schemaspublic static String getDDLFromFieldSchema(String structName, List<FieldSchema> fieldSchemas)
public static Properties getTableMetadata(Table table)
public static Properties getPartitionMetadata(Partition partition, Table table)
public static Properties getSchema(Partition part, Table table)
public static Properties getPartSchemaFromTableSchema(StorageDescriptor sd, StorageDescriptor tblsd, Map<String,String> parameters, String databaseName, String tableName, List<FieldSchema> partitionKeys, Properties tblSchema)
sd
- The Partition level Storage Descriptor.tblsd
- The Table level Storage Descriptor.parameters
- partition level parametersdatabaseName
- DB nametableName
- table namepartitionKeys
- partition columnstblSchema
- The table level schema from which this partition should be copied.public static Properties getSchema(StorageDescriptor sd, StorageDescriptor tblsd, Map<String,String> parameters, String databaseName, String tableName, List<FieldSchema> partitionKeys)
public static String getColumnNamesFromFieldSchema(List<FieldSchema> fieldSchemas)
public static String getColumnTypesFromFieldSchema(List<FieldSchema> fieldSchemas)
public static String getColumnCommentsFromFieldSchema(List<FieldSchema> fieldSchemas)
public static void makeDir(org.apache.hadoop.fs.Path path, HiveConf hiveConf) throws MetaException
MetaException
public static void startMetaStore(int port, HadoopThriftAuthBridge bridge) throws Exception
Exception
public static void startMetaStore(int port, HadoopThriftAuthBridge bridge, HiveConf hiveConf) throws Exception
Exception
public static int findFreePort() throws IOException
IOException
public static List<FieldSchema> getFieldsFromDeserializer(String tableName, Deserializer deserializer) throws SerDeException, MetaException
tableName
- deserializer
- SerDeException
MetaException
public static FieldSchema getFieldSchemaFromTypeInfo(String fieldName, TypeInfo typeInfo)
public static boolean isExternalTable(Table table)
table
- table of interestpublic static boolean isImmutableTable(Table table)
table
- table of interestpublic static boolean isArchived(Partition part)
public static org.apache.hadoop.fs.Path getOriginalLocation(Partition part)
public static boolean isNonNativeTable(Table table)
public static boolean isDirEmpty(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
path
- IOException
public static boolean pvalMatches(List<String> partial, List<String> full)
public static String getIndexTableName(String dbName, String baseTblName, String indexName)
public static boolean isIndexTable(Table table)
public static String makeFilterStringFromMap(Map<String,String> m)
m
- public static boolean isView(Table table)
public static Class<?> getClass(String rawStoreClassName) throws MetaException
MetaException
public static <T> T newInstance(Class<T> theClass, Class<?>[] parameterTypes, Object[] initargs)
theClass
- parameterTypes
- an array of parameterTypes for the constructorinitargs
- the list of arguments for the constructorpublic static void validatePartitionNameCharacters(List<String> partVals, Pattern partitionValidationPattern) throws MetaException
MetaException
public static boolean partitionNameHasValidCharacters(List<String> partVals, Pattern partitionValidationPattern)
public static boolean compareFieldColumns(List<FieldSchema> schema1, List<FieldSchema> schema2)
schema1:
- The first schema to be comparedschema2:
- The second schema to be comparedpublic static Map<String,String> getMetaStoreSaslProperties(HiveConf conf)
conf
- public static ProtectMode getProtectMode(Partition partition)
public static ProtectMode getProtectMode(Table table)
public static int getArchivingLevel(Partition part) throws MetaException
MetaException
public static Map<String,String> trimMapNulls(Map<String,String> dnMap, boolean retrieveMapNullsAsEmptyStrings)
public static ClassLoader addToClassPath(ClassLoader cloader, String[] newPaths) throws Exception
newPaths
- Array of classpath elementsException
Copyright © 2017 The Apache Software Foundation. All rights reserved.