示例#1
0
 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
 /** 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
 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
 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
  /** 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
    @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);
        }
      };
    }
 public Set<String> getSubSchemaNames() {
   return schema.getSubSchemaNames();
 }
 public Schema getSubSchema(String name) {
   return schema.getSubSchema(name);
 }
 public Set<String> getFunctionNames() {
   return schema.getFunctionNames();
 }
 public Collection<Function> getFunctions(String name) {
   return schema.getFunctions(name);
 }
 public Set<String> getTableNames() {
   return schema.getTableNames();
 }
 public Table getTable(String name) {
   return schema.getTable(name);
 }
 public Expression getExpression(SchemaPlus parentSchema, String name) {
   return schema.getExpression(parentSchema, name);
 }
 public boolean contentsHaveChangedSince(long lastCheck, long now) {
   return schema.contentsHaveChangedSince(lastCheck, now);
 }
 public boolean isMutable() {
   return schema.isMutable();
 }
示例#16
0
 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));
                 }
               }));
 }