org.apache.calcite.linq4j.BaseQueryable Java Examples

The following examples show how to use org.apache.calcite.linq4j.BaseQueryable. 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: TableFunctions.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String s) {
    BaseQueryable<RowType> queryable = new BaseQueryable<RowType>(null, getElementType(), null) {
        @Override
        public Enumerator<RowType> enumerator() {
            return Linq4j.enumerator(values);
        }
    };
    return (Queryable<T>) queryable;
}
 
Example #2
Source File: UDTFExplode.java    From marble with Apache License 2.0 4 votes vote down vote up
public static QueryableTable eval(List<String> params) {
  return new AbstractQueryableTable(String.class) {
    public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      RelDataType dataType = typeFactory.createSqlType(
          SqlTypeName.VARCHAR);
      return typeFactory.createStructType(
          Lists.newArrayList(dataType), Lists.newArrayList("s"));
    }

    public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
        SchemaPlus schema, String tableName) {
      BaseQueryable<String> queryable =
          new BaseQueryable<String>(null, String.class, null) {
            public Enumerator<String> enumerator() {
              return new Enumerator<String>() {
                int i = 0;
                int curI;
                String curS;

                public String current() {
                  return curS;
                }

                public boolean moveNext() {
                  if (params == null) {
                    return false;
                  }
                  if (i < params.size()) {
                    curI = i;
                    curS = params.get(i);
                    ++i;
                    return true;
                  } else {
                    return false;
                  }
                }

                public void reset() {
                  i = 0;
                }

                public void close() {
                }
              };
            }
          };
      //noinspection unchecked
      return (Queryable<T>) queryable;
    }
  };
}
 
Example #3
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** A function that generates a table that generates a sequence of
 * {@link IntString} values. */
public static QueryableTable generateStrings(final Integer count) {
  return new AbstractQueryableTable(IntString.class) {
    public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      return typeFactory.createJavaType(IntString.class);
    }

    public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
        SchemaPlus schema, String tableName) {
      BaseQueryable<IntString> queryable =
          new BaseQueryable<IntString>(null, IntString.class, null) {
            public Enumerator<IntString> enumerator() {
              return new Enumerator<IntString>() {
                static final String Z = "abcdefghijklm";

                int i = 0;
                int curI;
                String curS;

                public IntString current() {
                  return new IntString(curI, curS);
                }

                public boolean moveNext() {
                  if (i < count) {
                    curI = i;
                    curS = Z.substring(0, i % Z.length());
                    ++i;
                    return true;
                  } else {
                    return false;
                  }
                }

                public void reset() {
                  i = 0;
                }

                public void close() {
                }
              };
            }
          };
      //noinspection unchecked
      return (Queryable<T>) queryable;
    }
  };
}