本文整理汇总了Java中org.apache.calcite.DataContext类的典型用法代码示例。如果您正苦于以下问题:Java DataContext类的具体用法?Java DataContext怎么用?Java DataContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataContext类属于org.apache.calcite包,在下文中一共展示了DataContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createResultSet
import org.apache.calcite.DataContext; //导入依赖的package包/类
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, final Frame firstFrame) {
try {
final CalciteConnectionImpl connection = getConnection();
final AvaticaStatement statement = connection.createStatement();
final CalcitePrepare.CalciteSignature<Object> signature =
new CalcitePrepare.CalciteSignature<Object>("",
ImmutableList.<AvaticaParameter>of(), internalParameters, null,
columns, cursorFactory, ImmutableList.<RelCollation>of(), -1,
null, Meta.StatementType.SELECT) {
@Override
public Enumerable<Object> enumerable(
DataContext dataContext) {
return Linq4j.asEnumerable(firstFrame.rows);
}
};
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例2: enumerable
import org.apache.calcite.DataContext; //导入依赖的package包/类
public <T> Enumerable<T> enumerable(Meta.StatementHandle handle,
CalcitePrepare.CalciteSignature<T> signature) throws SQLException {
Map<String, Object> map = Maps.newLinkedHashMap();
AvaticaStatement statement = lookupStatement(handle);
final List<TypedValue> parameterValues =
TROJAN.getParameterValues(statement);
if (MetaImpl.checkParameterValueHasNull(parameterValues)) {
throw new SQLException("exception while executing query: unbound parameter");
}
for (Ord<TypedValue> o : Ord.zip(parameterValues)) {
map.put("?" + o.i, o.e.toLocal());
}
map.putAll(signature.internalParameters);
final DataContext dataContext = createDataContext(map);
return signature.enumerable(dataContext);
}
示例3: createResultSet
import org.apache.calcite.DataContext; //导入依赖的package包/类
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, final Frame firstFrame) {
try {
final QuarkConnectionImpl connection = getConnection();
final AvaticaStatement statement = connection.createStatement();
final CalcitePrepare.CalciteSignature<Object> signature =
new CalcitePrepare.CalciteSignature<Object>("",
ImmutableList.<AvaticaParameter>of(), internalParameters, null,
columns, cursorFactory, null, ImmutableList.<RelCollation>of(), -1,
null, Meta.StatementType.SELECT) {
@Override public Enumerable<Object> enumerable(
DataContext dataContext) {
return Linq4j.asEnumerable(firstFrame.rows);
}
};
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例4: bindVariable
import org.apache.calcite.DataContext; //导入依赖的package包/类
private void bindVariable(TupleFilter filter, DataContext dataContext) {
if (filter == null) {
return;
}
for (TupleFilter childFilter : filter.getChildren()) {
bindVariable(childFilter, dataContext);
}
if (filter instanceof CompareTupleFilter && dataContext != null) {
CompareTupleFilter compFilter = (CompareTupleFilter) filter;
for (Map.Entry<String, Object> entry : compFilter.getVariables().entrySet()) {
String variable = entry.getKey();
Object value = dataContext.get(variable);
if (value != null) {
String str = value.toString();
if (compFilter.getColumn().getType().isDateTimeFamily())
str = String.valueOf(DateFormat.stringToMillis(str));
compFilter.bindVariable(variable, str);
}
}
}
}
示例5: scan
import org.apache.calcite.DataContext; //导入依赖的package包/类
public Enumerable<Object[]> scan(DataContext root) {
final Random random = seed >= 0 ? new Random(seed) : new Random();
final Maze maze = new Maze(width, height);
final PrintWriter pw = Util.printWriter(System.out);
maze.layout(random, pw);
if (Maze.DEBUG) {
maze.print(pw, true);
}
return new AbstractEnumerable<Object[]>() {
public Enumerator<Object[]> enumerator() {
final Set<Integer> solutionSet;
if (solution) {
solutionSet = maze.solve(0, 0);
} else {
solutionSet = null;
}
return Linq4j.transform(maze.enumerator(solutionSet),
new Function1<String, Object[]>() {
public Object[] apply(String s) {
return new Object[] {s};
}
});
}
};
}
示例6: scan
import org.apache.calcite.DataContext; //导入依赖的package包/类
public Enumerable<Object[]> scan(DataContext root, List<RexNode> filters) {
final String[] filterValues = new String[fieldTypes.size()];
for (final Iterator<RexNode> i = filters.iterator(); i.hasNext();) {
final RexNode filter = i.next();
if (addFilter(filter, filterValues)) {
i.remove();
}
}
final int[] fields = CsvEnumerator.identityList(fieldTypes.size());
final AtomicBoolean cancelFlag = DataContext.Variable.CANCEL_FLAG.get(root);
return new AbstractEnumerable<Object[]>() {
public Enumerator<Object[]> enumerator() {
return new CsvEnumerator<>(source, cancelFlag, false, filterValues,
new CsvEnumerator.ArrayRowConverter(fieldTypes, fields));
}
};
}
示例7: createResultSet
import org.apache.calcite.DataContext; //导入依赖的package包/类
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, final Frame firstFrame) {
try {
final CalciteConnectionImpl connection = getConnection();
final AvaticaStatement statement = connection.createStatement();
final CalcitePrepare.CalciteSignature<Object> signature =
new CalcitePrepare.CalciteSignature<Object>("",
ImmutableList.<AvaticaParameter>of(), internalParameters, null,
columns, cursorFactory, null, ImmutableList.<RelCollation>of(), -1,
null, Meta.StatementType.SELECT) {
@Override public Enumerable<Object> enumerable(
DataContext dataContext) {
return Linq4j.asEnumerable(firstFrame.rows);
}
};
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例8: translateCondition
import org.apache.calcite.DataContext; //导入依赖的package包/类
public static Expression translateCondition(
RexProgram program,
JavaTypeFactory typeFactory,
BlockBuilder list,
InputGetter inputGetter,
Function1<String, InputGetter> correlates) {
if (program.getCondition() == null) {
return RexImpTable.TRUE_EXPR;
}
final ParameterExpression root = DataContext.ROOT;
RexToLixTranslator translator =
new RexToLixTranslator(program, typeFactory, root, inputGetter, list);
translator = translator.setCorrelates(correlates);
return translator.translate(
program.getCondition(),
RexImpTable.NullAs.FALSE);
}
示例9: createImplementor
import org.apache.calcite.DataContext; //导入依赖的package包/类
private static CallImplementor createImplementor(final Method method) {
return RexImpTable.createImplementor(
new ReflectiveCallNotNullImplementor(method) {
public Expression implement(RexToLixTranslator translator,
RexCall call, List<Expression> translatedOperands) {
Expression expr = super.implement(translator, call,
translatedOperands);
final Class<?> returnType = method.getReturnType();
if (QueryableTable.class.isAssignableFrom(returnType)) {
Expression queryable = Expressions.call(
Expressions.convert_(expr, QueryableTable.class),
BuiltInMethod.QUERYABLE_TABLE_AS_QUERYABLE.method,
Expressions.call(DataContext.ROOT,
BuiltInMethod.DATA_CONTEXT_GET_QUERY_PROVIDER.method),
Expressions.constant(null, SchemaPlus.class),
Expressions.constant(call.getOperator().getName(), String.class));
expr = Expressions.call(queryable,
BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method);
} else {
expr = Expressions.call(expr,
BuiltInMethod.SCANNABLE_TABLE_SCAN.method, DataContext.ROOT);
}
return expr;
}
}, NullPolicy.ANY, false);
}
示例10: isSatisfiable
import org.apache.calcite.DataContext; //导入依赖的package包/类
private boolean isSatisfiable(RexNode second, DataContext dataValues) {
if (dataValues == null) {
return false;
}
ImmutableList<RexNode> constExps = ImmutableList.of(second);
final RexExecutable exec =
executor.getExecutable(builder, constExps, rowType);
Object[] result;
exec.setDataContext(dataValues);
try {
result = exec.execute();
} catch (Exception e) {
// TODO: CheckSupport should not allow this exception to be thrown
// Need to monitor it and handle all the cases raising them.
LOGGER.warn("Exception thrown while checking if => {}: {}", second, e.getMessage());
return false;
}
return result != null
&& result.length == 1
&& result[0] instanceof Boolean
&& (Boolean) result[0];
}
示例11: of
import org.apache.calcite.DataContext; //导入依赖的package包/类
public static DataContext of(RelDataType rowType,
List<Pair<RexInputRef, RexNode>> usageList) {
final int size = rowType.getFieldList().size();
final Object[] values = new Object[size];
for (Pair<RexInputRef, RexNode> elem : usageList) {
Pair<Integer, ?> value = getValue(elem.getKey(), elem.getValue());
if (value == null) {
LOGGER.warn("{} is not handled for {} for checking implication",
elem.getKey(), elem.getValue());
return null;
}
int index = value.getKey();
values[index] = value.getValue();
}
return new VisitorDataContext(values);
}
示例12: field
import org.apache.calcite.DataContext; //导入依赖的package包/类
public Expression field(BlockBuilder list, int index, Type storageType) {
MethodCallExpression recFromCtx = Expressions.call(
DataContext.ROOT,
BuiltInMethod.DATA_CONTEXT_GET.method,
Expressions.constant("inputRecord"));
Expression recFromCtxCasted =
RexToLixTranslator.convert(recFromCtx, Object[].class);
IndexExpression recordAccess = Expressions.arrayIndex(recFromCtxCasted,
Expressions.constant(index));
if (storageType == null) {
final RelDataType fieldType =
rowType.getFieldList().get(index).getType();
storageType = ((JavaTypeFactory) typeFactory).getJavaClass(fieldType);
}
return RexToLixTranslator.convert(recordAccess, storageType);
}
示例13: compile
import org.apache.calcite.DataContext; //导入依赖的package包/类
private static Function1<DataContext, Object[]> compile(String code,
Object reason) {
try {
final ClassBodyEvaluator cbe = new ClassBodyEvaluator();
cbe.setClassName(GENERATED_CLASS_NAME);
cbe.setExtendedClass(Utilities.class);
cbe.setImplementedInterfaces(new Class[] {Function1.class, Serializable.class});
cbe.setParentClassLoader(RexExecutable.class.getClassLoader());
cbe.cook(new Scanner(null, new StringReader(code)));
Class c = cbe.getClazz();
//noinspection unchecked
final Constructor<Function1<DataContext, Object[]>> constructor =
c.getConstructor();
return constructor.newInstance();
} catch (CompileException | IOException | InstantiationException
| IllegalAccessException | InvocationTargetException
| NoSuchMethodException e) {
throw new RuntimeException("While compiling " + reason, e);
}
}
示例14: bindable
import org.apache.calcite.DataContext; //导入依赖的package包/类
/** Creates a {@link org.apache.calcite.runtime.Bindable} that interprets a
* given relational expression. */
public static ArrayBindable bindable(final RelNode rel) {
if (rel instanceof ArrayBindable) {
// E.g. if rel instanceof BindableRel
return (ArrayBindable) rel;
}
return new ArrayBindable() {
public Enumerable<Object[]> bind(DataContext dataContext) {
return new Interpreter(dataContext, rel);
}
public Class<Object[]> getElementType() {
return Object[].class;
}
};
}
示例15: createFilterable
import org.apache.calcite.DataContext; //导入依赖的package包/类
private static TableScanNode createFilterable(Compiler compiler,
TableScan rel, ImmutableList<RexNode> filters, ImmutableIntList projects,
FilterableTable filterableTable) {
final DataContext root = compiler.getDataContext();
final List<RexNode> mutableFilters = Lists.newArrayList(filters);
final Enumerable<Object[]> enumerable =
filterableTable.scan(root, mutableFilters);
for (RexNode filter : mutableFilters) {
if (!filters.contains(filter)) {
throw RESOURCE.filterableTableInventedFilter(filter.toString()).ex();
}
}
final Enumerable<Row> rowEnumerable = Enumerables.toRow(enumerable);
return createEnumerable(compiler, rel, rowEnumerable, null,
mutableFilters, projects);
}