Search in sources :

Example 1 with TableParamDef

use of org.apache.drill.exec.store.table.function.TableParamDef in project drill by apache.

the class AbstractSchema method getFunctions.

/**
 * For the given table names returns list of acceptable table functions
 * which are common for all Drill schemas. When overriding this method,
 * parent functions must be included first to be evaluated first.
 * If not included, parent functions won't be taken into account when creating table instance.
 *
 * @param name table name
 * @return list of table functions
 */
@Override
public Collection<Function> getFunctions(String name) {
    List<TableParamDef> parameters = getFunctionParameters();
    TableSignature signature = TableSignature.of(name, parameters);
    WithOptionsTableMacro function = new WithOptionsTableMacro(signature, arguments -> {
        Table table = getTable(name);
        if (table instanceof DrillTable) {
            return applyFunctionParameters((DrillTable) table, parameters, arguments);
        } else if (table == null) {
            return null;
        }
        throw new DrillRuntimeException(String.format("Table [%s] is not of Drill table instance. " + "Given instance is of [%s].", name, table.getClass().getName()));
    });
    return Collections.singletonList(function);
}
Also used : WithOptionsTableMacro(org.apache.drill.exec.store.table.function.WithOptionsTableMacro) DrillTable(org.apache.drill.exec.planner.logical.DrillTable) Table(org.apache.calcite.schema.Table) DrillTable(org.apache.drill.exec.planner.logical.DrillTable) TableParamDef(org.apache.drill.exec.store.table.function.TableParamDef) TableSignature(org.apache.drill.exec.store.table.function.TableSignature) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 2 with TableParamDef

use of org.apache.drill.exec.store.table.function.TableParamDef in project drill by apache.

the class FormatPluginOptionsDescriptor method presentParams.

/**
 * @return a readable String of the parameters and their names
 */
protected String presentParams() {
    StringBuilder sb = new StringBuilder("(");
    List<TableParamDef> params = params();
    for (int i = 0; i < params.size(); i++) {
        TableParamDef paramDef = params.get(i);
        if (i != 0) {
            sb.append(", ");
        }
        sb.append(paramDef.getName()).append(": ").append(paramDef.getType().getSimpleName());
    }
    sb.append(")");
    return sb.toString();
}
Also used : TableParamDef(org.apache.drill.exec.store.table.function.TableParamDef)

Aggregations

TableParamDef (org.apache.drill.exec.store.table.function.TableParamDef)2 Table (org.apache.calcite.schema.Table)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 DrillTable (org.apache.drill.exec.planner.logical.DrillTable)1 TableSignature (org.apache.drill.exec.store.table.function.TableSignature)1 WithOptionsTableMacro (org.apache.drill.exec.store.table.function.WithOptionsTableMacro)1