Java Code Examples for org.apache.calcite.linq4j.Linq4j#iterableEnumerator()

The following examples show how to use org.apache.calcite.linq4j.Linq4j#iterableEnumerator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstanceIdsByClassTable.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@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);
        }
    };
}
 
Example 2
Source File: OutboundReferencesTable.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@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);
        }
    };
}
 
Example 3
Source File: Interpreter.java    From calcite with Apache License 2.0 6 votes vote down vote up
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();
    }
  };
}
 
Example 4
Source File: Table.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
                                    SchemaPlus schema, String tableName) {
    return new AbstractTableQueryable<T>(queryProvider, schema, this, tableName) {
        public Enumerator<T> enumerator() {
            //noinspection unchecked
            return (Enumerator<T>) Linq4j.iterableEnumerator(
                () -> Iterators.transform(getModifiableCollection().iterator(), Table::toArray));
        }
    };
}
 
Example 5
Source File: QuarkResultSet.java    From quark with Apache License 2.0 5 votes vote down vote up
private Cursor createCursor(ColumnMetaData.AvaticaType elementType,
                            Iterable iterable) {
  final Enumerator enumerator = Linq4j.iterableEnumerator(iterable);
  //noinspection unchecked
  return !(elementType instanceof ColumnMetaData.StructType)
      || ((ColumnMetaData.StructType) elementType).columns.size() == 1
      ? new ObjectEnumeratorCursor(enumerator)
      : new ArrayEnumeratorCursor(enumerator);
}
 
Example 6
Source File: CalciteResultSet.java    From calcite with Apache License 2.0 5 votes vote down vote up
private Cursor createCursor(ColumnMetaData.AvaticaType elementType,
    Iterable iterable) {
  final Enumerator enumerator = Linq4j.iterableEnumerator(iterable);
  //noinspection unchecked
  return !(elementType instanceof ColumnMetaData.StructType)
      || ((ColumnMetaData.StructType) elementType).columns.size() == 1
      ? new ObjectEnumeratorCursor(enumerator)
      : new ArrayEnumeratorCursor(enumerator);
}