示例#1
0
 private SqlOperator toOp(String name, TableFunction fun) {
   List<RelDataType> argTypes = new ArrayList<RelDataType>();
   List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>();
   Parameter p;
   for (net.hydromatic.optiq.Parameter o :
       (List<net.hydromatic.optiq.Parameter>) fun.getParameters()) {
     argTypes.add(o.getType());
     typeFamilies.add(SqlTypeFamily.ANY);
   }
   return new SqlFunction(
       name,
       SqlKind.OTHER_FUNCTION,
       new ExplicitReturnTypeInference(typeFactory.createType(fun.getElementType())),
       new ExplicitOperandTypeInference(argTypes.toArray(new RelDataType[argTypes.size()])),
       new FamilyOperandTypeChecker(
           typeFamilies.toArray(new SqlTypeFamily[typeFamilies.size()])),
       null);
 }
示例#2
0
 public Object freeze(ColumnLoader.ValueSet valueSet) {
   final int chunksPerWord = 64 / bitCount;
   final List<Comparable> valueList = valueSet.values;
   final int valueCount = valueList.size();
   final int wordCount = (valueCount + (chunksPerWord - 1)) / chunksPerWord;
   final int remainingChunkCount = valueCount % chunksPerWord;
   final long[] longs = new long[wordCount];
   final int n = valueCount / chunksPerWord;
   int i;
   int k = 0;
   if (valueCount > 0 && valueList.get(0) instanceof Boolean) {
     @SuppressWarnings("unchecked")
     final List<Boolean> booleans = (List) valueSet.values;
     for (i = 0; i < n; i++) {
       long v = 0;
       for (int j = 0; j < chunksPerWord; j++) {
         v |= (booleans.get(k++) ? (1 << (bitCount * j)) : 0);
       }
       longs[i] = v;
     }
     if (remainingChunkCount > 0) {
       long v = 0;
       for (int j = 0; j < remainingChunkCount; j++) {
         v |= (booleans.get(k++) ? (1 << (bitCount * j)) : 0);
       }
       longs[i] = v;
     }
   } else {
     @SuppressWarnings("unchecked")
     final List<Number> numbers = (List) valueSet.values;
     for (i = 0; i < n; i++) {
       long v = 0;
       for (int j = 0; j < chunksPerWord; j++) {
         v |= (numbers.get(k++).longValue() << (bitCount * j));
       }
       longs[i] = v;
     }
     if (remainingChunkCount > 0) {
       long v = 0;
       for (int j = 0; j < remainingChunkCount; j++) {
         v |= (numbers.get(k++).longValue() << (bitCount * j));
       }
       longs[i] = v;
     }
   }
   return longs;
 }
示例#3
0
 private Collection<Function> getFunctionsFrom(List<String> names) {
   final List<Function> functions2 = Lists.newArrayList();
   final List<? extends List<String>> schemaNameList;
   if (names.size() > 1) {
     // If name is qualified, ignore path.
     schemaNameList = ImmutableList.of(ImmutableList.<String>of());
   } else {
     OptiqSchema schema = getSchema(defaultSchema);
     if (schema == null) {
       schemaNameList = ImmutableList.of();
     } else {
       schemaNameList = schema.getPath();
     }
   }
   for (List<String> schemaNames : schemaNameList) {
     OptiqSchema schema = getSchema(Iterables.concat(schemaNames, Util.skipLast(names)));
     if (schema != null) {
       final String name = Util.last(names);
       functions2.addAll(schema.getFunctions(name, true));
     }
   }
   return functions2;
 }
示例#4
0
 public Statistic getStatistic() {
   return Statistics.of(list.size(), Collections.<BitSet>emptyList());
 }
示例#5
0
  <T> PrepareResult<T> prepare_(
      Context context, String sql, Queryable<T> queryable, Type elementType) {
    final JavaTypeFactory typeFactory = context.getTypeFactory();
    OptiqCatalogReader catalogReader = new OptiqCatalogReader(context.getRootSchema(), typeFactory);
    final OptiqPreparingStmt preparingStmt =
        new OptiqPreparingStmt(catalogReader, typeFactory, context.getRootSchema());
    preparingStmt.setResultCallingConvention(CallingConvention.ENUMERABLE);

    final RelDataType x;
    final PreparedResult preparedResult;
    if (sql != null) {
      assert queryable == null;
      SqlParser parser = new SqlParser(sql);
      SqlNode sqlNode;
      try {
        sqlNode = parser.parseQuery();
      } catch (SqlParseException e) {
        throw new RuntimeException("parse failed", e);
      }
      final Schema rootSchema = context.getRootSchema();
      SqlValidator validator =
          new SqlValidatorImpl(
              new ChainedSqlOperatorTable(
                  Arrays.<SqlOperatorTable>asList(
                      SqlStdOperatorTable.instance(),
                      new MySqlOperatorTable(rootSchema, typeFactory))),
              catalogReader,
              typeFactory,
              SqlConformance.Default) {};
      preparedResult = preparingStmt.prepareSql(sqlNode, Object.class, validator, true);
      x = validator.getValidatedNodeType(sqlNode);
    } else {
      assert queryable != null;
      x = context.getTypeFactory().createType(elementType);
      preparedResult = preparingStmt.prepareQueryable(queryable, x);
    }

    // TODO: parameters
    final List<Parameter> parameters = Collections.emptyList();
    // TODO: column meta data
    final List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    RelDataType jdbcType = makeStruct(typeFactory, x);
    for (RelDataTypeField field : jdbcType.getFields()) {
      RelDataType type = field.getType();
      SqlTypeName sqlTypeName = type.getSqlTypeName();
      columns.add(
          new ColumnMetaData(
              columns.size(),
              false,
              true,
              false,
              false,
              type.isNullable() ? 1 : 0,
              true,
              0,
              field.getName(),
              field.getName(),
              null,
              sqlTypeName.allowsPrec() && false ? type.getPrecision() : -1,
              sqlTypeName.allowsScale() ? type.getScale() : -1,
              null,
              null,
              sqlTypeName.getJdbcOrdinal(),
              sqlTypeName.getName(),
              true,
              false,
              false,
              null));
    }
    return new PrepareResult<T>(sql, parameters, columns, (Enumerable<T>) preparedResult.execute());
  }