Search in sources :

Example 1 with FunctionExprNode

use of org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode in project drill by axbaretto.

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
 */
private static InfoSchemaFilter createInfoSchemaFilter(final LikeFilter catalogNameFilter, final LikeFilter schemaNameFilter, final LikeFilter tableNameFilter, List<String> tableTypeFilter, final LikeFilter columnNameFilter) {
    FunctionExprNode exprNode = createLikeFunctionExprNode(CATS_COL_CATALOG_NAME, catalogNameFilter);
    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;
}
Also used : InfoSchemaFilter(org.apache.drill.exec.store.ischema.InfoSchemaFilter) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode)

Example 2 with FunctionExprNode

use of org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode 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;
}
Also used : LikeFilter(org.apache.drill.exec.proto.UserProtos.LikeFilter) InfoSchemaFilter(org.apache.drill.exec.store.ischema.InfoSchemaFilter) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode)

Example 3 with FunctionExprNode

use of org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode in project drill by axbaretto.

the class MetadataProvider method createInFunctionExprNode.

/**
 * Helper method to create {@link FunctionExprNode} from {@code List<String>}.
 * @param fieldName Name of the filed on which the like expression is applied.
 * @param valuesFilter a list of values
 * @return {@link FunctionExprNode} for given arguments. Null if the <code>valuesFilter</code> is null.
 */
private static FunctionExprNode createInFunctionExprNode(String fieldName, List<String> valuesFilter) {
    if (valuesFilter == null) {
        return null;
    }
    ImmutableList.Builder<ExprNode> nodes = ImmutableList.builder();
    nodes.add(new FieldExprNode(fieldName));
    for (String type : valuesFilter) {
        nodes.add(new ConstantExprNode(type));
    }
    return new FunctionExprNode(IN_FUNCTION, nodes.build());
}
Also used : ExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ExprNode) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode) FieldExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode) ConstantExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ConstantExprNode) ImmutableList(com.google.common.collect.ImmutableList) FieldExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode) ConstantExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ConstantExprNode)

Example 4 with FunctionExprNode

use of org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode in project drill by apache.

the class MetadataProvider method createInFunctionExprNode.

/**
 * Helper method to create {@link FunctionExprNode} from {@code List<String>}.
 * @param fieldName Name of the filed on which the like expression is applied.
 * @param valuesFilter a list of values
 * @return {@link FunctionExprNode} for given arguments. Null if the <code>valuesFilter</code> is null.
 */
private static FunctionExprNode createInFunctionExprNode(String fieldName, List<String> valuesFilter) {
    if (valuesFilter == null) {
        return null;
    }
    ImmutableList.Builder<ExprNode> nodes = ImmutableList.builder();
    nodes.add(new FieldExprNode(fieldName));
    for (String type : valuesFilter) {
        nodes.add(new ConstantExprNode(type));
    }
    return new FunctionExprNode(IN_FUNCTION, nodes.build());
}
Also used : ExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ExprNode) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode) FieldExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode) ConstantExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ConstantExprNode) ImmutableList(org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList) FieldExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode) FunctionExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode) ConstantExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.ConstantExprNode)

Aggregations

FunctionExprNode (org.apache.drill.exec.store.ischema.InfoSchemaFilter.FunctionExprNode)4 InfoSchemaFilter (org.apache.drill.exec.store.ischema.InfoSchemaFilter)2 ConstantExprNode (org.apache.drill.exec.store.ischema.InfoSchemaFilter.ConstantExprNode)2 ExprNode (org.apache.drill.exec.store.ischema.InfoSchemaFilter.ExprNode)2 FieldExprNode (org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 LikeFilter (org.apache.drill.exec.proto.UserProtos.LikeFilter)1 ImmutableList (org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList)1