use of org.apache.drill.exec.proto.UserProtos.LikeFilter in project drill by axbaretto.
the class DrillMetaImpl method serverGetSchemas.
private MetaResultSet serverGetSchemas(String catalog, Pat schemaPattern) {
final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
return new MetadataAdapter<MetaImpl.MetaSchema, GetSchemasResp, SchemaMetadata>(MetaImpl.MetaSchema.class) {
@Override
protected RequestStatus getStatus(GetSchemasResp response) {
return response.getStatus();
}
@Override
protected List<SchemaMetadata> getResult(GetSchemasResp response) {
return response.getSchemasList();
}
@Override
protected DrillPBError getError(GetSchemasResp response) {
return response.getError();
}
@Override
protected MetaSchema adapt(SchemaMetadata value) {
return new MetaImpl.MetaSchema(value.getCatalogName(), value.getSchemaName());
}
}.getMeta(connection.getClient().getSchemas(catalogNameFilter, schemaNameFilter));
}
use of org.apache.drill.exec.proto.UserProtos.LikeFilter in project drill by axbaretto.
the class DrillMetaImpl method serverGetColumns.
private MetaResultSet serverGetColumns(String catalog, Pat schemaPattern, Pat tableNamePattern, Pat columnNamePattern) {
final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
final LikeFilter tableNameFilter = newLikeFilter(tableNamePattern);
final LikeFilter columnNameFilter = newLikeFilter(columnNamePattern);
return new MetadataAdapter<MetaColumn, GetColumnsResp, ColumnMetadata>(MetaColumn.class) {
@Override
protected RequestStatus getStatus(GetColumnsResp response) {
return response.getStatus();
}
@Override
protected DrillPBError getError(GetColumnsResp response) {
return response.getError();
}
@Override
protected List<ColumnMetadata> getResult(GetColumnsResp response) {
return response.getColumnsList();
}
private int getDataType(ColumnMetadata value) {
switch(value.getDataType()) {
case "ARRAY":
return Types.ARRAY;
case "BIGINT":
return Types.BIGINT;
case "BINARY":
return Types.BINARY;
case "BINARY LARGE OBJECT":
return Types.BLOB;
case "BINARY VARYING":
return Types.VARBINARY;
case "BIT":
return Types.BIT;
case "BOOLEAN":
return Types.BOOLEAN;
case "CHARACTER":
return Types.CHAR;
// Resolve: Not seen in Drill yet. Can it appear?:
case "CHARACTER LARGE OBJECT":
return Types.CLOB;
case "CHARACTER VARYING":
return Types.VARCHAR;
// Resolve: Not seen in Drill yet. Can it appear?:
case "DATALINK":
return Types.DATALINK;
case "DATE":
return Types.DATE;
case "DECIMAL":
return Types.DECIMAL;
// Resolve: Not seen in Drill yet. Can it appear?:
case "DISTINCT":
return Types.DISTINCT;
case "DOUBLE":
case "DOUBLE PRECISION":
return Types.DOUBLE;
case "FLOAT":
return Types.FLOAT;
case "INTEGER":
return Types.INTEGER;
case "INTERVAL":
return Types.OTHER;
// Resolve: Not seen in Drill yet. Can it ever appear?:
case "JAVA_OBJECT":
return Types.JAVA_OBJECT;
// Resolve: Not seen in Drill yet. Can it appear?:
case "LONGNVARCHAR":
return Types.LONGNVARCHAR;
// Resolve: Not seen in Drill yet. Can it appear?:
case "LONGVARBINARY":
return Types.LONGVARBINARY;
// Resolve: Not seen in Drill yet. Can it appear?:
case "LONGVARCHAR":
return Types.LONGVARCHAR;
case "MAP":
return Types.OTHER;
// Resolve: Not seen in Drill yet. Can it appear?:
case "NATIONAL CHARACTER":
return Types.NCHAR;
// Resolve: Not seen in Drill yet. Can it appear?:
case "NATIONAL CHARACTER LARGE OBJECT":
return Types.NCLOB;
// Resolve: Not seen in Drill yet. Can it appear?:
case "NATIONAL CHARACTER VARYING":
return Types.NVARCHAR;
// mapping.
case "NULL":
return Types.NULL;
// (No NUMERIC--Drill seems to map any to DECIMAL currently.)
case "NUMERIC":
return Types.NUMERIC;
// Resolve: Unexpectedly, has appeared in Drill. Should it?
case "OTHER":
return Types.OTHER;
case "REAL":
return Types.REAL;
// Resolve: Not seen in Drill yet. Can it appear?:
case "REF":
return Types.REF;
// Resolve: Not seen in Drill yet. Can it appear?:
case "ROWID":
return Types.ROWID;
case "SMALLINT":
return Types.SMALLINT;
// Resolve: Not seen in Drill yet. Can it appear?:
case "SQLXML":
return Types.SQLXML;
case "STRUCT":
return Types.STRUCT;
case "TIME":
return Types.TIME;
case "TIMESTAMP":
return Types.TIMESTAMP;
case "TINYINT":
return Types.TINYINT;
default:
return Types.OTHER;
}
}
Integer getDecimalDigits(ColumnMetadata value) {
switch(value.getDataType()) {
case "TINYINT":
case "SMALLINT":
case "INTEGER":
case "BIGINT":
case "DECIMAL":
case "NUMERIC":
return value.hasNumericScale() ? value.getNumericScale() : null;
case "REAL":
return DECIMAL_DIGITS_REAL;
case "FLOAT":
return DECIMAL_DIGITS_FLOAT;
case "DOUBLE":
return DECIMAL_DIGITS_DOUBLE;
case "DATE":
case "TIME":
case "TIMESTAMP":
case "INTERVAL":
return value.getDateTimePrecision();
default:
return null;
}
}
private Integer getNumPrecRadix(ColumnMetadata value) {
switch(value.getDataType()) {
case "TINYINT":
case "SMALLINT":
case "INTEGER":
case "BIGINT":
case "DECIMAL":
case "NUMERIC":
case "REAL":
case "FLOAT":
case "DOUBLE":
return value.getNumericPrecisionRadix();
case "INTERVAL":
return RADIX_INTERVAL;
case "DATE":
case "TIME":
case "TIMESTAMP":
return RADIX_DATETIME;
default:
return null;
}
}
private int getNullable(ColumnMetadata value) {
if (!value.hasIsNullable()) {
return DatabaseMetaData.columnNullableUnknown;
}
return value.getIsNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls;
}
private String getIsNullable(ColumnMetadata value) {
if (!value.hasIsNullable()) {
return "";
}
return value.getIsNullable() ? "YES" : "NO";
}
private Integer getCharOctetLength(ColumnMetadata value) {
if (!value.hasCharMaxLength()) {
return null;
}
switch(value.getDataType()) {
case "CHARACTER":
case "CHARACTER LARGE OBJECT":
case "CHARACTER VARYING":
case "LONGVARCHAR":
case "LONGNVARCHAR":
case "NATIONAL CHARACTER":
case "NATIONAL CHARACTER LARGE OBJECT":
case "NATIONAL CHARACTER VARYING":
return value.getCharOctetLength();
default:
return null;
}
}
@Override
protected MetaColumn adapt(ColumnMetadata value) {
return new MetaColumn(value.getCatalogName(), value.getSchemaName(), value.getTableName(), value.getColumnName(), // It might require the full SQL type
getDataType(value), value.getDataType(), value.getColumnSize(), getDecimalDigits(value), getNumPrecRadix(value), getNullable(value), getCharOctetLength(value), value.getOrdinalPosition(), getIsNullable(value));
}
}.getMeta(connection.getClient().getColumns(catalogNameFilter, schemaNameFilter, tableNameFilter, columnNameFilter));
}
use of org.apache.drill.exec.proto.UserProtos.LikeFilter in project drill by apache.
the class DrillMetaImpl method serverGetSchemas.
private MetaResultSet serverGetSchemas(String catalog, Pat schemaPattern) {
final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
return new MetadataAdapter<MetaImpl.MetaSchema, GetSchemasResp, SchemaMetadata>(MetaImpl.MetaSchema.class) {
@Override
protected RequestStatus getStatus(GetSchemasResp response) {
return response.getStatus();
}
@Override
protected List<SchemaMetadata> getResult(GetSchemasResp response) {
return response.getSchemasList();
}
@Override
protected DrillPBError getError(GetSchemasResp response) {
return response.getError();
}
@Override
protected MetaSchema adapt(SchemaMetadata value) {
return new MetaImpl.MetaSchema(value.getCatalogName(), value.getSchemaName());
}
}.getMeta(connection.getClient().getSchemas(catalogNameFilter, schemaNameFilter));
}
use of org.apache.drill.exec.proto.UserProtos.LikeFilter in project drill by apache.
the class DrillMetaImpl method serverGetTables.
private MetaResultSet serverGetTables(String catalog, final Pat schemaPattern, final Pat tableNamePattern, final List<String> typeList) {
// Catalog is not a pattern
final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
final LikeFilter tableNameFilter = newLikeFilter(tableNamePattern);
return new MetadataAdapter<MetaImpl.MetaTable, GetTablesResp, TableMetadata>(MetaTable.class) {
@Override
protected RequestStatus getStatus(GetTablesResp response) {
return response.getStatus();
}
@Override
protected DrillPBError getError(GetTablesResp response) {
return response.getError();
}
@Override
protected List<TableMetadata> getResult(GetTablesResp response) {
return response.getTablesList();
}
@Override
protected MetaImpl.MetaTable adapt(TableMetadata protoValue) {
return new MetaImpl.MetaTable(protoValue.getCatalogName(), protoValue.getSchemaName(), protoValue.getTableName(), protoValue.getType());
}
}.getMeta(connection.getClient().getTables(catalogNameFilter, schemaNameFilter, tableNameFilter, typeList));
}
use of org.apache.drill.exec.proto.UserProtos.LikeFilter in project drill by apache.
the class MetadataProvider method createInfoSchemaFilter.
/**
* Helper method to create a {@link InfoSchemaFilter} that combines the given filters with an AND.
*
* @param catalogNameFilter Optional filter on <code>catalog name</code>
* @param schemaNameFilter Optional filter on <code>schema name</code>
* @param tableNameFilter Optional filter on <code>table name</code>
* @param tableTypeFilter Optional filter on <code>table type</code>
* @param columnNameFilter Optional filter on <code>column name</code>
* @return information schema filter
*/
private static InfoSchemaFilter createInfoSchemaFilter(LikeFilter catalogNameFilter, LikeFilter schemaNameFilter, LikeFilter tableNameFilter, List<String> tableTypeFilter, LikeFilter columnNameFilter) {
FunctionExprNode exprNode = createLikeFunctionExprNode(CATS_COL_CATALOG_NAME, catalogNameFilter);
// convert like filter condition elements to lower case
if (schemaNameFilter != null) {
LikeFilter.Builder builder = LikeFilter.newBuilder();
if (schemaNameFilter.hasPattern()) {
builder.setPattern(schemaNameFilter.getPattern().toLowerCase());
}
if (schemaNameFilter.hasEscape()) {
builder.setEscape(schemaNameFilter.getEscape().toLowerCase());
}
schemaNameFilter = builder.build();
}
exprNode = combineFunctions(AND_FUNCTION, exprNode, combineFunctions(OR_FUNCTION, createLikeFunctionExprNode(SHRD_COL_TABLE_SCHEMA, schemaNameFilter), createLikeFunctionExprNode(SCHS_COL_SCHEMA_NAME, schemaNameFilter)));
exprNode = combineFunctions(AND_FUNCTION, exprNode, createLikeFunctionExprNode(SHRD_COL_TABLE_NAME, tableNameFilter));
exprNode = combineFunctions(AND_FUNCTION, exprNode, createInFunctionExprNode(TBLS_COL_TABLE_TYPE, tableTypeFilter));
exprNode = combineFunctions(AND_FUNCTION, exprNode, createLikeFunctionExprNode(COLS_COL_COLUMN_NAME, columnNameFilter));
return exprNode != null ? new InfoSchemaFilter(exprNode) : null;
}
Aggregations