Example #1
0
 public List<SqlMoniker> getAllSchemaObjectNames(List<String> names) {
   List<SqlMoniker> result;
   switch (names.size()) {
     case 0:
       // looking for schema names
       result = new ArrayList<SqlMoniker>();
       for (MockSchema schema : schemas.values()) {
         result.add(new SqlMonikerImpl(schema.name, SqlMonikerType.Schema));
       }
       return result;
     case 1:
       // looking for table names in the given schema
       MockSchema schema = schemas.get(names.get(0));
       if (schema == null) {
         return Collections.emptyList();
       }
       result = new ArrayList<SqlMoniker>();
       for (String tableName : schema.tableNames) {
         result.add(new SqlMonikerImpl(tableName, SqlMonikerType.Table));
       }
       return result;
     default:
       return Collections.emptyList();
   }
 }
Example #2
0
 public List<SqlOperator> lookupOperatorOverloads(
     SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax) {
   if (syntax != SqlSyntax.Function) {
     return Collections.emptyList();
   }
   // FIXME: ignoring prefix of opName
   String name = opName.names[opName.names.length - 1];
   List<TableFunction> tableFunctions = rootSchema.getTableFunctions(name);
   if (tableFunctions.isEmpty()) {
     return Collections.emptyList();
   }
   return toOps(name, tableFunctions);
 }
Example #3
0
    public PreparedResult prepareQueryable(Queryable queryable, RelDataType resultType) {
      queryString = null;
      Class runtimeContextClass = Object.class;
      final Argument[] arguments = {new Argument(connectionVariable, runtimeContextClass, null)};
      ClassDeclaration decl = init(arguments);

      final RelOptQuery query = new RelOptQuery(planner);
      final RelOptCluster cluster =
          query.createCluster(env, rexBuilder.getTypeFactory(), rexBuilder);

      RelNode rootRel = new LixToRelTranslator(cluster).translate(queryable);

      if (timingTracer != null) {
        timingTracer.traceTime("end sql2rel");
      }

      final RelDataType jdbcType = makeStruct(rexBuilder.getTypeFactory(), resultType);
      fieldOrigins = Collections.nCopies(jdbcType.getFieldCount(), null);

      // Structured type flattening, view expansion, and plugging in
      // physical storage.
      rootRel = flattenTypes(rootRel, true);

      // Trim unused fields.
      rootRel = trimUnusedFields(rootRel);

      rootRel = optimize(resultType, rootRel);
      containsJava = treeContainsJava(rootRel);

      if (timingTracer != null) {
        timingTracer.traceTime("end optimization");
      }

      return implement(resultType, rootRel, SqlKind.SELECT, decl, arguments);
    }
Example #4
0
 private static List<Expression> simpleList(BlockExpression expression) {
   Expression simple = Blocks.simple(expression);
   if (simple instanceof NewExpression) {
     NewExpression newExpression = (NewExpression) simple;
     return newExpression.arguments;
   } else {
     return Collections.singletonList(simple);
   }
 }
Example #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());
  }
Example #6
0
 public List<RelCollation> getCollationList() {
   return Collections.emptyList();
 }