本文整理汇总了Java中org.apache.calcite.linq4j.Enumerator类的典型用法代码示例。如果您正苦于以下问题:Java Enumerator类的具体用法?Java Enumerator怎么用?Java Enumerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Enumerator类属于org.apache.calcite.linq4j包,在下文中一共展示了Enumerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: asQueryable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override
public Queryable<Integer> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) {
return new AbstractTableQueryable<Integer>(queryProvider, schemaPlus, this, tableName) {
@Override
public Enumerator<Integer> enumerator() {
FluentIterable<Integer> it = FluentIterable
.from(classesList.getClasses())
.transformAndConcat(
new Function<IClass, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(IClass input) {
try {
return Ints.asList(input
.getObjectIds());
} catch (SnapshotException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
});
return Linq4j.iterableEnumerator(it);
}
};
}
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:26,代码来源:InstanceIdsByClassTable.java
示例2: asQueryable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override
public Queryable<Object[]> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) {
return new AbstractTableQueryable<Object[]>(queryProvider, schemaPlus, this, tableName) {
@Override
public Enumerator<Object[]> enumerator() {
FluentIterable<Object[]> it = FluentIterable
.from(references)
.transform(new Function<NamedReference, Object[]>() {
@Nullable
@Override
public Object[] apply(@Nullable NamedReference namedReference) {
HeapReference ref = null;
try {
ref = HeapReference.valueOf(namedReference.getObject());
} catch (SnapshotException e) {
e.printStackTrace();
}
return new Object[]{namedReference.getName(), ref};
}
});
return Linq4j.iterableEnumerator(it);
}
};
}
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:26,代码来源:OutboundReferencesTable.java
示例3: enumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/** Generates a list of lines representing the maze in text form. */
public Enumerator<String> enumerator(final Set<Integer> solutionSet) {
final CellContent cellContent;
if (solutionSet == null) {
cellContent = CellContent.SPACE;
} else {
cellContent = new CellContent() {
public String get(int c) {
return solutionSet.contains(c) ? "* " : " ";
}
};
}
return new Enumerator<String>() {
int i = -1;
final StringBuilder b = new StringBuilder();
final StringBuilder b2 = new StringBuilder();
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:Maze.java
示例4: scan
import org.apache.calcite.linq4j.Enumerator; //导入依赖的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};
}
});
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:MazeTable.java
示例5: scan
import org.apache.calcite.linq4j.Enumerator; //导入依赖的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));
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:CsvFilterableTable.java
示例6: find
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override protected Enumerable<Object> find(String index, List<String> ops,
List<Map.Entry<String, Class>> fields) {
final String dbName = index;
final String queryString = "{" + Util.toString(ops, "", ", ", "") + "}";
final Function1<SearchHit, Object> getter = Elasticsearch2Enumerator.getter(fields);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
final Iterator<SearchHit> cursor = client.prepareSearch(dbName).setTypes(typeName)
.setSource(queryString).execute().actionGet().getHits().iterator();
return new Elasticsearch2Enumerator(cursor, getter);
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:Elasticsearch2Table.java
示例7: getElementType
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/**
* Returns the element type of a {@link Collection}, {@link Iterable}
* (including {@link org.apache.calcite.linq4j.Queryable Queryable} and
* {@link org.apache.calcite.linq4j.Enumerable Enumerable}), {@link Iterator},
* {@link Enumerator}, or an array.
*
* <p>Returns null if the type is not one of these.</p>
*/
public static Type getElementType(Type type) {
if (type instanceof ArrayType) {
return ((ArrayType) type).getComponentType();
}
if (type instanceof GenericArrayType) {
return ((GenericArrayType) type).getGenericComponentType();
}
Class clazz = toClass(type);
if (clazz.isArray()) {
return clazz.getComponentType();
}
if (Collection.class.isAssignableFrom(clazz)
|| Iterable.class.isAssignableFrom(clazz)
|| Iterator.class.isAssignableFrom(clazz)
|| Enumerator.class.isAssignableFrom(clazz)) {
if (type instanceof ParameterizedType) {
return ((ParameterizedType) type).getActualTypeArguments()[0];
}
return Object.class;
}
return null;
}
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:Types.java
示例8: myEnumerable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
private Enumerable<String> myEnumerable(final int[] closes, final int size) {
return new AbstractEnumerable<String>() {
public Enumerator<String> enumerator() {
return new Enumerator<String>() {
int i = 0;
public String current() {
return "x";
}
public boolean moveNext() {
return i++ < size;
}
public void reset() {
}
public void close() {
++closes[0];
}
};
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:Linq4jTest.java
示例9: testTransformEnumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testTransformEnumerator() {
final List<String> strings = Arrays.asList("one", "two", "three");
final Function1<String, Integer> func = new Function1<String, Integer>() {
public Integer apply(String a0) {
return a0.length();
}
};
final Enumerator<Integer> enumerator =
Linq4j.transform(Linq4j.enumerator(strings), func);
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(3));
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(3));
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(5));
assertThat(enumerator.moveNext(), is(false));
final Enumerator<Integer> enumerator2 =
Linq4j.transform(Linq4j.<String>emptyEnumerator(), func);
assertThat(enumerator2.moveNext(), is(false));
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:Linq4jTest.java
示例10: checkCast
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
private void checkCast(Enumerator<Integer> enumerator) {
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(2), enumerator.current());
assertTrue(enumerator.moveNext());
assertNull(enumerator.current());
assertTrue(enumerator.moveNext());
try {
Object x = enumerator.current();
fail("expected error, got " + x);
} catch (ClassCastException e) {
// good
}
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(5), enumerator.current());
assertFalse(enumerator.moveNext());
enumerator.reset();
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(2), enumerator.current());
}
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:Linq4jTest.java
示例11: testList2
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testList2() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerator<String> enumerator = Linq4j.enumerator(experience);
assertThat(enumerator.getClass().getName(), endsWith("ListEnumerator"));
assertThat(count(enumerator), equalTo(3));
final Enumerable<String> listEnumerable = Linq4j.asEnumerable(experience);
final Enumerator<String> listEnumerator = listEnumerable.enumerator();
assertThat(listEnumerator.getClass().getName(),
endsWith("ListEnumerator"));
assertThat(count(listEnumerator), equalTo(3));
final Enumerable<String> linkedListEnumerable =
Linq4j.asEnumerable(Lists.newLinkedList(experience));
final Enumerator<String> iterableEnumerator =
linkedListEnumerable.enumerator();
assertThat(iterableEnumerator.getClass().getName(),
endsWith("IterableEnumerator"));
assertThat(count(iterableEnumerator), equalTo(3));
}
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:Linq4jTest.java
示例12: testDefaultIfEmpty
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testDefaultIfEmpty() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerable<String> notEmptyEnumerable = Linq4j.asEnumerable(experience).defaultIfEmpty();
final Enumerator<String> notEmptyEnumerator = notEmptyEnumerable.enumerator();
notEmptyEnumerator.moveNext();
assertEquals("jimi", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("mitch", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("noel", notEmptyEnumerator.current());
final Enumerable<String> emptyEnumerable =
Linq4j.asEnumerable(Linq4j.<String>emptyEnumerable()).defaultIfEmpty();
final Enumerator<String> emptyEnumerator = emptyEnumerable.enumerator();
assertTrue(emptyEnumerator.moveNext());
assertNull(emptyEnumerator.current());
assertFalse(emptyEnumerator.moveNext());
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:Linq4jTest.java
示例13: testDefaultIfEmpty2
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testDefaultIfEmpty2() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerable<String> notEmptyEnumerable =
Linq4j.asEnumerable(experience).defaultIfEmpty("dummy");
final Enumerator<String> notEmptyEnumerator = notEmptyEnumerable.enumerator();
notEmptyEnumerator.moveNext();
assertEquals("jimi", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("mitch", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("noel", notEmptyEnumerator.current());
final Enumerable<String> emptyEnumerable =
Linq4j.asEnumerable(Linq4j.<String>emptyEnumerable()).defaultIfEmpty("N/A");
final Enumerator<String> emptyEnumerator = emptyEnumerable.enumerator();
assertTrue(emptyEnumerator.moveNext());
assertEquals("N/A", emptyEnumerator.current());
assertFalse(emptyEnumerator.moveNext());
}
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:Linq4jTest.java
示例14: testJoin
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public void testJoin(CorrelateJoinType joinType, Integer[][] expected) {
Enumerable<Integer[]> join =
Linq4j.asEnumerable(ImmutableList.of(1, 2, 3, 10, 20, 30))
.correlateJoin(joinType,
new Function1<Integer, Enumerable<Integer>>() {
public Enumerable<Integer> apply(Integer a0) {
if (a0 == 1 || a0 == 10) {
return Linq4j.emptyEnumerable();
}
if (a0 == 2 || a0 == 20) {
return Linq4j.singletonEnumerable(a0 * 10);
}
if (a0 == 3 || a0 == 30) {
return Linq4j.asEnumerable(
ImmutableList.of(-a0 * 10, -a0 * 20));
}
throw new IllegalArgumentException(
"Unexpected input " + a0);
}
}, SELECT_BOTH);
for (int i = 0; i < 2; i++) {
Enumerator<Integer[]> e = join.enumerator();
checkResults(e, expected);
e.close();
}
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:CorrelateJoinTest.java
示例15: find
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/** Executes a "find" operation on the underlying collection.
*
* <p>For example,
* <code>zipsTable.find("{state: 'OR'}", "{city: 1, zipcode: 1}")</code></p>
*
* @param mongoDb MongoDB connection
* @param filterJson Filter JSON string, or null
* @param projectJson Project JSON string, or null
* @param fields List of fields to project; or null to return map
* @return Enumerator of results
*/
private Enumerable<Object> find(MongoDatabase mongoDb, String filterJson,
String projectJson, List<Map.Entry<String, Class>> fields) {
final MongoCollection collection =
mongoDb.getCollection(collectionName);
final Bson filter =
filterJson == null ? null : BsonDocument.parse(filterJson);
final Bson project =
projectJson == null ? null : BsonDocument.parse(projectJson);
final Function1<Document, Object> getter = MongoEnumerator.getter(fields);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
@SuppressWarnings("unchecked") final FindIterable<Document> cursor =
collection.find(filter).projection(project);
return new MongoEnumerator(cursor.iterator(), getter);
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:MongoTable.java
示例16: aggregate
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/** Executes an "aggregate" operation on the underlying collection.
*
* <p>For example:
* <code>zipsTable.aggregate(
* "{$filter: {state: 'OR'}",
* "{$group: {_id: '$city', c: {$sum: 1}, p: {$sum: '$pop'}}}")
* </code></p>
*
* @param mongoDb MongoDB connection
* @param fields List of fields to project; or null to return map
* @param operations One or more JSON strings
* @return Enumerator of results
*/
private Enumerable<Object> aggregate(final MongoDatabase mongoDb,
final List<Map.Entry<String, Class>> fields,
final List<String> operations) {
final List<Bson> list = new ArrayList<>();
for (String operation : operations) {
list.add(BsonDocument.parse(operation));
}
final Function1<Document, Object> getter =
MongoEnumerator.getter(fields);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
final Iterator<Document> resultIterator;
try {
resultIterator = mongoDb.getCollection(collectionName)
.aggregate(list).iterator();
} catch (Exception e) {
throw new RuntimeException("While running MongoDB query "
+ Util.toString(operations, "[", ",\n", "]"), e);
}
return new MongoEnumerator(resultIterator, getter);
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:MongoTable.java
示例17: asQueryable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider,
SchemaPlus schema, String tableName) {
return new AbstractQueryable<T>() {
public Type getElementType() {
return elementType;
}
public Expression getExpression() {
return expression;
}
public QueryProvider getProvider() {
return queryProvider;
}
public Iterator<T> iterator() {
//noinspection unchecked
return list.iterator();
}
public Enumerator<T> enumerator() {
//noinspection unchecked
return Linq4j.enumerator(list);
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:ListTable.java
示例18: enumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public Enumerator<Object[]> enumerator() {
start();
final NodeInfo nodeInfo = nodes.get(rootRel);
final Enumerator<Row> rows;
if (nodeInfo.rowEnumerable != null) {
rows = nodeInfo.rowEnumerable.enumerator();
} else {
final ArrayDeque<Row> queue =
Iterables.getOnlyElement(nodeInfo.sinks.values()).list;
rows = Linq4j.iterableEnumerator(queue);
}
return new TransformedEnumerator<Row, Object[]>(rows) {
protected Object[] transform(Row row) {
return row.getValues();
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:Interpreter.java
示例19: enumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public Enumerator<Integer> enumerator() {
return new Enumerator<Integer>() {
int current = start - 1;
public Integer current() {
if (current >= end) {
throw new NoSuchElementException();
}
return current;
}
public boolean moveNext() {
++current;
return current < end;
}
public void reset() {
current = start - 1;
}
public void close() {
}
};
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:RangeTable.java
示例20: testFlatListProduct
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testFlatListProduct() {
final List<Enumerator<List<String>>> list = new ArrayList<>();
list.add(Linq4j.enumerator(l2(l1("a"), l1("b"))));
list.add(Linq4j.enumerator(l3(l2("x", "p"), l2("y", "q"), l2("z", "r"))));
final Enumerable<FlatLists.ComparableList<String>> product =
SqlFunctions.product(list, 3, false);
int n = 0;
FlatLists.ComparableList<String> previous = FlatLists.of();
for (FlatLists.ComparableList<String> strings : product) {
if (n++ == 1) {
assertThat(strings.size(), is(3));
assertThat(strings.get(0), is("a"));
assertThat(strings.get(1), is("y"));
assertThat(strings.get(2), is("q"));
}
if (previous != null) {
assertTrue(previous.compareTo(strings) < 0);
}
previous = strings;
}
assertThat(n, is(6));
}
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:UtilTest.java
注:本文中的org.apache.calcite.linq4j.Enumerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论