本文整理汇总了Java中org.apache.calcite.linq4j.function.Function2类的典型用法代码示例。如果您正苦于以下问题:Java Function2类的具体用法?Java Function2怎么用?Java Function2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function2类属于org.apache.calcite.linq4j.function包,在下文中一共展示了Function2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
@Override
public StatementExecutionResult execute(TableSpaceManager tableSpaceManager,
TransactionContext transactionContext,
StatementEvaluationContext context, boolean lockRequired, boolean forWrite) throws StatementExecutionException {
ScanResult resLeft = (ScanResult) left.execute(tableSpaceManager, transactionContext,
context, lockRequired, forWrite);
transactionContext = new TransactionContext(resLeft.transactionId);
ScanResult resRight = (ScanResult) right.execute(tableSpaceManager, transactionContext,
context, lockRequired, forWrite);
final long resTransactionId = resRight.transactionId;
final String[] fieldNamesFromLeft = resLeft.dataScanner.getFieldNames();
final String[] fieldNamesFromRight = resRight.dataScanner.getFieldNames();
final Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection = resultProjection(fieldNamesFromLeft, fieldNamesFromRight);
Enumerable<DataAccessor> result = EnumerableDefaults.thetaJoin(resLeft.dataScanner.createEnumerable(),
resRight.dataScanner.createEnumerable(),
predicate(resultProjection, context), resultProjection,
generateNullsOnLeft,
generateNullsOnRight
);
EnumerableDataScanner joinedScanner = new EnumerableDataScanner(resTransactionId, fieldNames, columns, result);
return new ScanResult(resTransactionId, joinedScanner);
}
示例2: createCopyHook
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
private Function2<RelNode, RelNode, Void> createCopyHook() {
return new Function2<RelNode, RelNode, Void>() {
public Void apply(RelNode oldNode, RelNode newNode) {
if (cm.mapRefRelToCorVar.containsKey(oldNode)) {
cm.mapRefRelToCorVar.putAll(newNode, cm.mapRefRelToCorVar.get(oldNode));
}
if (oldNode instanceof LogicalCorrelate && newNode instanceof LogicalCorrelate) {
LogicalCorrelate oldCor = (LogicalCorrelate) oldNode;
CorrelationId c = oldCor.getCorrelationId();
if (cm.mapCorVarToCorRel.get(c) == oldNode) {
cm.mapCorVarToCorRel.put(c, newNode);
}
if (generatedCorRels.contains(oldNode)) {
generatedCorRels.add((LogicalCorrelate) newNode);
}
}
return null;
}
};
}
示例3: join
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
/**
* Correlates the elements of two sequences based on
* matching keys. A specified {@code EqualityComparer<TSource>} is used to
* compare keys.
*/
public static <TSource, TInner, TKey, TResult> Enumerable<TResult> join(
Enumerable<TSource> outer, Enumerable<TInner> inner,
Function1<TSource, TKey> outerKeySelector,
Function1<TInner, TKey> innerKeySelector,
Function2<TSource, TInner, TResult> resultSelector,
EqualityComparer<TKey> comparer, boolean generateNullsOnLeft,
boolean generateNullsOnRight) {
return join_(
outer,
inner,
outerKeySelector,
innerKeySelector,
resultSelector,
comparer,
generateNullsOnLeft,
generateNullsOnRight);
}
示例4: mergeJoin
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
/** Joins two inputs that are sorted on the key. */
public static <TSource, TInner, TKey extends Comparable<TKey>, TResult> Enumerable<TResult>
mergeJoin(final Enumerable<TSource> outer,
final Enumerable<TInner> inner,
final Function1<TSource, TKey> outerKeySelector,
final Function1<TInner, TKey> innerKeySelector,
final Function2<TSource, TInner, TResult> resultSelector,
boolean generateNullsOnLeft,
boolean generateNullsOnRight) {
assert !generateNullsOnLeft : "not implemented";
assert !generateNullsOnRight : "not implemented";
return new AbstractEnumerable<TResult>() {
public Enumerator<TResult> enumerator() {
return new MergeJoinEnumerator<>(outer.enumerator(),
inner.enumerator(), outerKeySelector, innerKeySelector,
resultSelector);
}
};
}
示例5: testSelectManyWithIndexableSelector
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
@Test public void testSelectManyWithIndexableSelector() {
final int[] indexRef = new int[]{0};
final List<String> nameSeqs =
Linq4j.asEnumerable(depts)
.selectMany(new Function2<Department, Integer, Enumerable<Employee>>() {
public Enumerable<Employee> apply(Department element, Integer index) {
assertEquals(indexRef[0], index.longValue());
indexRef[0] = index + 1;
return Linq4j.asEnumerable(element.employees);
}
})
.select(
new Function2<Employee, Integer, String>() {
public String apply(Employee v1, Integer v2) {
return "#" + v2 + ": " + v1.name;
}
})
.toList();
assertEquals(
"[#0: Fred, #1: Eric, #2: Janet, #3: Bill]", nameSeqs.toString());
}
示例6: testGroupByWithKeySelectorAndResultSelector
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
@Test public void testGroupByWithKeySelectorAndResultSelector() {
String s =
Linq4j.asEnumerable(emps)
.groupBy(EMP_DEPTNO_SELECTOR, new Function2<Integer, Enumerable<Employee>, String>() {
public String apply(Integer key, Enumerable<Employee> group) {
return String.format(Locale.ROOT, "%s: %s", key,
stringJoin("+", group.select(new Function1<Employee, String>() {
public String apply(Employee element) {
return element.name;
}
})));
}
})
.toList()
.toString();
assertEquals(
"[10: Fred+Eric+Janet, 30: Bill]",
s);
}
示例7: HepPlanner
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
/**
* Creates a new HepPlanner with the option to keep the graph a
* tree(noDAG=true) or allow DAG(noDAG=false).
*
* @param program program controlling rule application
* @param onCopyHook Function to call when a node is copied
*/
public HepPlanner(
HepProgram program,
Context context,
boolean noDAG,
Function2<RelNode, RelNode, Void> onCopyHook,
RelOptCostFactory costFactory) {
super(costFactory, context);
this.mainProgram = program;
this.onCopyHook =
Util.first(onCopyHook, Functions.<RelNode, RelNode, Void>ignore2());
mapDigestToVertex = new HashMap<>();
graph = DefaultDirectedGraph.create();
// NOTE jvs 24-Apr-2006: We use LinkedHashSet here and below
// in order to provide deterministic behavior.
allRules = new LinkedHashSet<>();
this.noDAG = noDAG;
}
示例8: createCopyHook
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
private Function2<RelNode, RelNode, Void> createCopyHook() {
return new Function2<RelNode, RelNode, Void>() {
public Void apply(RelNode oldNode, RelNode newNode) {
if (cm.mapRefRelToCorRef.containsKey(oldNode)) {
cm.mapRefRelToCorRef.putAll(newNode,
cm.mapRefRelToCorRef.get(oldNode));
}
if (oldNode instanceof LogicalCorrelate
&& newNode instanceof LogicalCorrelate) {
LogicalCorrelate oldCor = (LogicalCorrelate) oldNode;
CorrelationId c = oldCor.getCorrelationId();
if (cm.mapCorToCorRel.get(c) == oldNode) {
cm.mapCorToCorRel.put(c, newNode);
}
if (generatedCorRels.contains(oldNode)) {
generatedCorRels.add((LogicalCorrelate) newNode);
}
}
return null;
}
};
}
示例9: groupBy
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
/**
* Groups the elements of a sequence according to a
* specified key selector function, initializing an accumulator for each
* group and adding to it each time an element with the same key is seen.
* Creates a result value from each accumulator and its key using a
* specified function. Key values are compared by using a
* specified comparer.
*/
public static <TSource, TKey, TAccumulate, TResult> Enumerable<TResult> groupBy(
Enumerable<TSource> enumerable, Function1<TSource, TKey> keySelector,
Function0<TAccumulate> accumulatorInitializer,
Function2<TAccumulate, TSource, TAccumulate> accumulatorAdder,
Function2<TKey, TAccumulate, TResult> resultSelector,
EqualityComparer<TKey> comparer) {
return groupBy_(
new WrapMap<>(
new Function0<Map<Wrapped<TKey>, TAccumulate>>() {
public Map<Wrapped<TKey>, TAccumulate> apply() {
return new HashMap<>();
}
},
comparer),
enumerable,
keySelector,
accumulatorInitializer,
accumulatorAdder,
resultSelector);
}
示例10: testGroupByWithKeySelectorAndElementSelectorAndResultSelector
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
@Test public void testGroupByWithKeySelectorAndElementSelectorAndResultSelector() {
String s =
Linq4j.asEnumerable(emps)
.groupBy(EMP_DEPTNO_SELECTOR, EMP_NAME_SELECTOR,
new Function2<Integer, Enumerable<String>, String>() {
public String apply(Integer key, Enumerable<String> group) {
return String.format(Locale.ROOT, "%s: %s", key,
stringJoin("+", group));
}
})
.toList()
.toString();
assertEquals(
"[10: Fred+Eric+Janet, 30: Bill]",
s);
}
示例11: predicate
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
private Predicate2<DataAccessor, DataAccessor> predicate(
Function2<DataAccessor, DataAccessor, DataAccessor> projection,
StatementEvaluationContext context) {
return (DataAccessor v0, DataAccessor v1) -> {
DataAccessor currentRow = projection.apply(v0, v1);
return SQLRecordPredicate.toBoolean(condition.evaluate(currentRow, context));
};
}
示例12: resultProjection
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
private Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection(
String[] fieldNamesFromLeft,
String[] fieldNamesFromRight) {
final DataAccessor nullsOnLeft = DataAccessor.ALL_NULLS(fieldNamesFromLeft);
final DataAccessor nullsOnRight = DataAccessor.ALL_NULLS(fieldNamesFromRight);
return (DataAccessor a, DataAccessor b)
-> new ConcatenatedDataAccessor(fieldNames,
a != null ? a : nullsOnLeft,
b != null ? b : nullsOnRight);
}
示例13: resultProjection
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
private Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection(
String[] fieldNamesFromLeft,
String[] fieldNamesFromRight) {
DataAccessor nullsOnLeft = DataAccessor.ALL_NULLS(fieldNamesFromLeft);
DataAccessor nullsOnRight = DataAccessor.ALL_NULLS(fieldNamesFromRight);
return (DataAccessor a, DataAccessor b)
-> new ConcatenatedDataAccessor(fieldNames,
a != null ? a : nullsOnLeft,
b != null ? b : nullsOnRight);
}
示例14: testGroupJoin
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
@Test public void testGroupJoin() {
// Note #1: Group join is a "left join": "bad employees" are filtered
// out, but empty departments are not.
// Note #2: Order of departments is preserved.
String s =
Linq4j.asEnumerable(depts)
.groupJoin(
Linq4j.asEnumerable(emps)
.concat(Linq4j.asEnumerable(badEmps)),
DEPT_DEPTNO_SELECTOR,
EMP_DEPTNO_SELECTOR,
new Function2<Department, Enumerable<Employee>, String>() {
public String apply(Department v1, Enumerable<Employee> v2) {
final StringBuilder buf = new StringBuilder("[");
int n = 0;
for (Employee employee : v2) {
if (n++ > 0) {
buf.append(", ");
}
buf.append(employee.name);
}
return buf.append("] work(s) in ").append(v1.name)
.toString();
}
})
.toList()
.toString();
assertEquals(
"[[Fred, Eric, Janet] work(s) in Sales, "
+ "[] work(s) in HR, "
+ "[Bill] work(s) in Marketing]",
s);
}
示例15: groupJoin
import org.apache.calcite.linq4j.function.Function2; //导入依赖的package包/类
public <TInner, TKey, TResult> Queryable<TResult> groupJoin(
Queryable<T> source,
Enumerable<TInner> inner,
FunctionExpression<Function1<T, TKey>> outerKeySelector,
FunctionExpression<Function1<TInner, TKey>> innerKeySelector,
FunctionExpression<Function2<T, Enumerable<TInner>, TResult>>
resultSelector) {
throw new UnsupportedOperationException();
}