public class TableUtil extends Object
Constructor and Description |
---|
TableUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
assertNumericalCols(TableSchema tableSchema,
String... selectedCols)
Check whether colTypes of the
selectedCols is numerical, if not, throw
exception. |
static void |
assertSelectedColExist(String[] tableCols,
String... selectedCols)
Check whether
selectedCols exist or not, if not exist, throw exception. |
static void |
assertStringCols(TableSchema tableSchema,
String... selectedCols)
Check whether colTypes of the
selectedCols is string, if not, throw exception. |
static void |
assertVectorCols(TableSchema tableSchema,
String... selectedCols)
Check whether colTypes of the
selectedCols is vector, if not, throw exception. |
static String |
columnsToSqlClause(String[] colNames)
Convert column name array to SQL clause.
|
static int |
findColIndex(String[] tableCols,
String targetCol)
Find the index of
targetCol in string array tableCols . |
static int |
findColIndex(TableSchema tableSchema,
String targetCol)
Find the index of
targetCol from the tableSchema . |
static int[] |
findColIndices(String[] tableCols,
String[] targetCols)
Find the indices of
targetCols in string array tableCols . |
static int[] |
findColIndices(TableSchema tableSchema,
String[] targetCols)
Find the indices of
targetCols from the tableSchema . |
static TypeInformation<?> |
findColType(TableSchema tableSchema,
String targetCol)
Find the type of the
targetCol . |
static TypeInformation<?>[] |
findColTypes(TableSchema tableSchema,
String[] targetCols)
Find the types of the
targetCols . |
static String |
format(String[] colNames,
List<Row> data)
format the column names and rows in table as markdown.
|
static String |
formatRows(Row row)
format the row as body of markdown.
|
static String |
formatTitle(String[] colNames)
format the column names as header of markdown.
|
static String[] |
getCategoricalCols(TableSchema tableSchema,
String[] featureCols,
String[] categoricalCols)
Get the columns from featureCols who are included in the
categoricalCols , and
the columns whose types are string or boolean. |
static String[] |
getNumericCols(TableSchema tableSchema)
Return the columns in the table whose types are numeric.
|
static String[] |
getNumericCols(TableSchema tableSchema,
String[] excludeCols)
Return the columns in the table whose types are numeric and are not included in the
excludeCols.
|
static String[] |
getStringCols(TableSchema tableSchema)
Return the columns in the table whose types are string.
|
static String[] |
getStringCols(TableSchema tableSchema,
String[] excludeCols)
Return the columns in the table whose types are string and are not included in the
excludeCols.
|
static String |
getTempTableName()
Return a temp table named with prefix `temp_`, follow by a random UUID.
|
static boolean |
isString(TypeInformation<?> dataType)
Determine whether it is a string type.
|
static boolean |
isSupportedNumericType(TypeInformation<?> dataType)
Determine whether it is number type, number type includes double, long, byte, int, float and
short.
|
static boolean |
isVector(TypeInformation<?> dataType)
Determine whether it is a vector type.
|
public static String getTempTableName()
UUID hyphens ("-") will be replaced by underscores ("_").
public static int findColIndex(String[] tableCols, String targetCol)
targetCol
in string array tableCols
. It will
ignore the case of the tableCols.tableCols
- a string array among which to find the targetCol.targetCol
- the targetCol to find.public static int findColIndex(TableSchema tableSchema, String targetCol)
targetCol
from the tableSchema
.tableSchema
- the TableSchema among which to find the targetCol.targetCol
- the targetCols to find.public static int[] findColIndices(String[] tableCols, String[] targetCols)
targetCols
in string array tableCols
. If
targetCols
is null, it will be replaced by the tableCols
tableCols
- a string array among which to find the targetCols.targetCols
- the targetCols to find.public static int[] findColIndices(TableSchema tableSchema, String[] targetCols)
targetCols
from the tableSchema
.tableSchema
- the TableSchema among which to find the targetCols.targetCols
- the targetCols to find.public static TypeInformation<?>[] findColTypes(TableSchema tableSchema, String[] targetCols)
targetCols
. If the targetCol not exist, return null.tableSchema
- TableSchema.targetCols
- the targetCols to find.public static TypeInformation<?> findColType(TableSchema tableSchema, String targetCol)
targetCol
. If the targetCol not exist, return null.tableSchema
- TableSchematargetCol
- the targetCol to find.public static boolean isSupportedNumericType(TypeInformation<?> dataType)
dataType
- the dataType to determine.public static boolean isString(TypeInformation<?> dataType)
dataType
- the dataType to determine.public static boolean isVector(TypeInformation<?> dataType)
dataType
- the dataType to determine.public static void assertSelectedColExist(String[] tableCols, String... selectedCols)
selectedCols
exist or not, if not exist, throw exception.tableCols
- a string array among which to find the target selectedCols.selectedCols
- the selectedCols to assert.public static void assertNumericalCols(TableSchema tableSchema, String... selectedCols)
selectedCols
is numerical, if not, throw
exception.tableSchema
- TableSchemaselectedCols
- the selectedCols to assert.public static void assertStringCols(TableSchema tableSchema, String... selectedCols)
selectedCols
is string, if not, throw exception.tableSchema
- TableSchemaselectedCols
- the selectedCol to assert.public static void assertVectorCols(TableSchema tableSchema, String... selectedCols)
selectedCols
is vector, if not, throw exception.tableSchema
- TableSchemaselectedCols
- the selectedCol to assert.isVector(TypeInformation)
public static String[] getStringCols(TableSchema tableSchema)
tableSchema
- TableSchemapublic static String[] getStringCols(TableSchema tableSchema, String[] excludeCols)
If excludeCols
is null, return all the string columns.
tableSchema
- TableSchema.excludeCols
- The columns who are not considered.public static String[] getNumericCols(TableSchema tableSchema)
tableSchema
- TableSchemapublic static String[] getNumericCols(TableSchema tableSchema, String[] excludeCols)
If excludeCols
is null, return all the numeric columns.
tableSchema
- TableSchema.excludeCols
- the columns who are not considered.public static String[] getCategoricalCols(TableSchema tableSchema, String[] featureCols, String[] categoricalCols)
categoricalCols
, and
the columns whose types are string or boolean.
If categoricalCols
is null, return all the categorical columns.
for example: In FeatureHasher which projects a number of categorical or numerical features into a feature vector of a specified dimension needs to identify the categorical features. And the column which is the string or boolean must be categorical. We need to find these columns as categorical when user do not specify the types(categorical or numerical).
tableSchema
- TableSchema.featureCols
- the columns to chosen from.categoricalCols
- the columns which are included in the final result whatever the types
of them are. And it must be a subset of featureCols.public static String formatTitle(String[] colNames)
public static String format(String[] colNames, List<Row> data)
public static String columnsToSqlClause(String[] colNames)
For example, columns "{a, b, c}" will be converted into a SQL-compatible select string section: "`a`, `b`, `c`".
colNames
- columns to convertCopyright © 2014–2021 The Apache Software Foundation. All rights reserved.