コード例 #1
0
ファイル: OptiqPrepareImpl.java プロジェクト: cwensel/optiq
 public RelOptTableImpl getTable(final String[] names) {
   List<Pair<String, Object>> pairs = new ArrayList<Pair<String, Object>>();
   Schema schema2 = schema;
   for (int i = 0; i < names.length; i++) {
     final String name = names[i];
     Schema subSchema = schema2.getSubSchema(name);
     if (subSchema != null) {
       pairs.add(Pair.<String, Object>of(name, subSchema));
       schema2 = subSchema;
       continue;
     }
     final Table table = schema2.getTable(name);
     if (table != null) {
       pairs.add(Pair.<String, Object>of(name, table));
       if (i != names.length - 1) {
         // not enough objects to match all names
         return null;
       }
       return new RelOptTableImpl(
           this, typeFactory.createType(table.getElementType()), names, table);
     }
     return null;
   }
   return null;
 }
コード例 #2
0
ファイル: ListTable.java プロジェクト: norrislee/optiq
 /** Creates a ListTable. */
 public ListTable(
     Schema schema,
     Type elementType,
     RelDataType relDataType,
     Expression expression,
     List<T> list) {
   super(schema.getQueryProvider(), elementType, expression);
   this.schema = schema;
   this.relDataType = relDataType;
   this.list = list;
 }
コード例 #3
0
ファイル: OptiqSchema.java プロジェクト: jaltekruse/optiq
 public final Table getTable(String tableName, boolean caseSensitive) {
   if (caseSensitive) {
     return compositeTableMap.get(tableName);
   } else {
     final TableEntry tableEntry = tableMapInsensitive.get(tableName);
     if (tableEntry != null) {
       return tableEntry.getTable();
     }
     final FunctionEntry entry = nullaryFunctionMapInsensitive.get(tableName);
     if (entry != null) {
       return ((TableMacro) entry.getFunction()).apply(ImmutableList.of());
     }
     for (String name : schema.getTableNames()) {
       if (name.equalsIgnoreCase(tableName)) {
         return schema.getTable(name);
       }
     }
     return null;
   }
 }
コード例 #4
0
ファイル: OptiqPrepareImpl.java プロジェクト: cwensel/optiq
 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);
 }
コード例 #5
0
ファイル: ArrayTable.java プロジェクト: sreev/optiq
  /** Creates an ArrayTable. */
  public ArrayTable(
      Schema schema,
      Type elementType,
      RelDataType relDataType,
      Expression expression,
      List<Pair<Representation, Object>> pairs,
      int size) {
    super(schema.getQueryProvider(), elementType, expression);
    this.schema = schema;
    this.relDataType = relDataType;
    this.pairs = pairs;
    this.size = size;

    assert relDataType.getFieldCount() == pairs.size();
  }
コード例 #6
0
ファイル: OptiqPrepareImpl.java プロジェクト: cwensel/optiq
    @Override
    protected PreparedExecution implement(
        RelDataType rowType,
        RelNode rootRel,
        SqlKind sqlKind,
        ClassDeclaration decl,
        Argument[] args) {
      RelDataType resultType = rootRel.getRowType();
      boolean isDml = sqlKind.belongsTo(SqlKind.DML);
      javaCompiler = createCompiler();
      EnumerableRelImplementor relImplementor =
          getRelImplementor(rootRel.getCluster().getRexBuilder());
      BlockExpression expr = relImplementor.implementRoot((EnumerableRel) rootRel);
      ParameterExpression root0 = Expressions.parameter(DataContext.class, "root0");
      String s =
          Expressions.toString(
              Blocks.create(
                  Expressions.declare(
                      Modifier.FINAL, (ParameterExpression) schema.getExpression(), root0),
                  expr),
              false);

      final Executable executable;
      try {
        executable =
            (Executable)
                ExpressionEvaluator.createFastScriptEvaluator(
                    s, Executable.class, new String[] {root0.name});
      } catch (Exception e) {
        throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e);
      }

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

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

      return new PreparedExecution(
          null, rootRel, resultType, isDml, mapTableModOp(isDml, sqlKind), null) {
        public Object execute() {
          return executable.execute(schema);
        }
      };
    }
コード例 #7
0
 public Set<String> getSubSchemaNames() {
   return schema.getSubSchemaNames();
 }
コード例 #8
0
 public Schema getSubSchema(String name) {
   return schema.getSubSchema(name);
 }
コード例 #9
0
 public Set<String> getFunctionNames() {
   return schema.getFunctionNames();
 }
コード例 #10
0
 public Collection<Function> getFunctions(String name) {
   return schema.getFunctions(name);
 }
コード例 #11
0
 public Set<String> getTableNames() {
   return schema.getTableNames();
 }
コード例 #12
0
 public Table getTable(String name) {
   return schema.getTable(name);
 }
コード例 #13
0
 public Expression getExpression(SchemaPlus parentSchema, String name) {
   return schema.getExpression(parentSchema, name);
 }
コード例 #14
0
 public boolean contentsHaveChangedSince(long lastCheck, long now) {
   return schema.contentsHaveChangedSince(lastCheck, now);
 }
コード例 #15
0
 public boolean isMutable() {
   return schema.isMutable();
 }
コード例 #16
0
ファイル: OptiqSchema.java プロジェクト: jaltekruse/optiq
 public OptiqSchema(OptiqSchema parent, final Schema schema, String name) {
   this.parent = parent;
   this.schema = schema;
   this.name = name;
   assert (parent == null) == (this instanceof OptiqRootSchema);
   //noinspection unchecked
   this.compositeTableMap =
       CompositeMap.of(
           Maps.transformValues(
               tableMap,
               new com.google.common.base.Function<TableEntry, Table>() {
                 public Table apply(TableEntry input) {
                   return input.getTable();
                 }
               }),
           Maps.transformValues(
               Multimaps.filterEntries(
                       functionMap,
                       new Predicate<Map.Entry<String, FunctionEntry>>() {
                         public boolean apply(Map.Entry<String, FunctionEntry> entry) {
                           final Function function = entry.getValue().getFunction();
                           return function instanceof TableMacro
                               && function.getParameters().isEmpty();
                         }
                       })
                   .asMap(),
               new com.google.common.base.Function<Collection<FunctionEntry>, Table>() {
                 public Table apply(Collection<FunctionEntry> input) {
                   // At most one function with zero parameters.
                   final TableMacro tableMacro =
                       (TableMacro) input.iterator().next().getFunction();
                   return tableMacro.apply(ImmutableList.of());
                 }
               }),
           Compatible.INSTANCE.asMap(
               schema.getTableNames(),
               new com.google.common.base.Function<String, Table>() {
                 public Table apply(String input) {
                   return schema.getTable(input);
                 }
               }));
   // TODO: include schema's functions in this map.
   this.compositeFunctionMap =
       Multimaps.transformValues(
           functionMap,
           new com.google.common.base.Function<FunctionEntry, Function>() {
             public Function apply(FunctionEntry input) {
               return input.getFunction();
             }
           });
   //noinspection unchecked
   this.compositeSubSchemaMap =
       CompositeMap.of(
           subSchemaMap,
           Compatible.INSTANCE.asMap(
               schema.getSubSchemaNames(),
               new com.google.common.base.Function<String, OptiqSchema>() {
                 public OptiqSchema apply(String name) {
                   return add(name, schema.getSubSchema(name));
                 }
               }));
 }