Java Code Examples for org.apache.calcite.linq4j.Enumerator#current()

The following examples show how to use org.apache.calcite.linq4j.Enumerator#current() . 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: Linq4jTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: Linq4jTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static int count(Enumerator<String> enumerator) {
  int n = 0;
  while (enumerator.moveNext()) {
    if (enumerator.current() != null) {
      ++n;
    }
  }
  return n;
}
 
Example 3
Source File: EnumerableInterpretable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void run() throws InterruptedException {
  final Enumerator<Object[]> enumerator = enumerable.enumerator();
  while (enumerator.moveNext()) {
    Object[] values = enumerator.current();
    sink.send(Row.of(values));
  }
}
 
Example 4
Source File: SqlFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Function that, given a certain List containing single-item structs (i.e. arrays / lists with
 * a single item), builds an Enumerable that returns those single items inside the structs.
 */
public static Function1<Object, Enumerable<Comparable>> flatList() {
  return inputObject -> {
    final List list = (List) inputObject;
    final Enumerator<List<Object>> enumerator = Linq4j.enumerator(list);
    return new AbstractEnumerable<Comparable>() {
      public Enumerator<Comparable> enumerator() {
        return new Enumerator<Comparable>() {

          @Override public boolean moveNext() {
            return enumerator.moveNext();
          }

          @Override public Comparable current() {
            final Object element = enumerator.current();
            final Comparable comparable;
            if (element.getClass().isArray()) {
              comparable = (Comparable) ((Object[]) element)[0];
            } else {
              comparable = (Comparable) ((List) element).get(0);
            }
            return comparable;
          }

          @Override public void reset() {
            enumerator.reset();
          }

          @Override public void close() {
            enumerator.close();
          }
        };
      }
    };
  };
}