Java Code Examples for org.apache.calcite.jdbc.CalcitePrepare#SparkHandler

The following examples show how to use org.apache.calcite.jdbc.CalcitePrepare#SparkHandler . 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: HiveEnumerableInterpretable.java    From marble with Apache License 2.0 5 votes vote down vote up
public static Bindable toBindable(Map<String, Object> parameters,
    CalcitePrepare.SparkHandler spark, EnumerableRel rel,
    EnumerableRel.Prefer prefer) {
  HiveEnumerableRelImplementor relImplementor =
      new HiveEnumerableRelImplementor(rel.getCluster().getRexBuilder(),
          parameters);

  final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
  String s = Expressions.toString(expr.memberDeclarations, "\n", false);

  if (CalcitePrepareImpl.DEBUG) {
    Util.debugCode(System.out, s);
  }

  Hook.JAVA_PLAN.run(s);

  try {
    if (spark != null && spark.enabled()) {
      return spark.compile(expr, s);
    } else {
      return getBindable(expr, s,
          rel.getRowType().getFieldCount());
    }
  } catch (Exception e) {
    throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n"
        + s, e);
  }
}
 
Example 2
Source File: QueryContext.java    From quark with Apache License 2.0 5 votes vote down vote up
public CalcitePrepare.Context getPrepareContext() {
  return new CalcitePrepare.Context() {

    @Override
    public JavaTypeFactory getTypeFactory() {
      return typeFactory;
    }

    @Override
    public CalciteSchema getRootSchema() {
      return CalciteSchema.from(rootSchema);
    }

    @Override
    public List<String> getDefaultSchemaPath() {
      return defaultSchema;
    }

    @Override
    public CalciteConnectionConfig config() {
      return cfg;
    }

    @Override
    public CalcitePrepare.SparkHandler spark() {
      return CalcitePrepare.Dummy.getSparkHandler(false);
    }

    @Override
    public DataContext getDataContext() {
      return null;
    }
  };
}
 
Example 3
Source File: EnumerableInterpretable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static Bindable toBindable(Map<String, Object> parameters,
    CalcitePrepare.SparkHandler spark, EnumerableRel rel,
    EnumerableRel.Prefer prefer) {
  EnumerableRelImplementor relImplementor =
      new EnumerableRelImplementor(rel.getCluster().getRexBuilder(),
          parameters);

  final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
  String s = Expressions.toString(expr.memberDeclarations, "\n", false);

  if (CalciteSystemProperty.DEBUG.value()) {
    Util.debugCode(System.out, s);
  }

  Hook.JAVA_PLAN.run(s);

  try {
    if (spark != null && spark.enabled()) {
      return spark.compile(expr, s);
    } else {
      return getBindable(expr, s, rel.getRowType().getFieldCount());
    }
  } catch (Exception e) {
    throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n"
        + s, e);
  }
}
 
Example 4
Source File: InterpretableRel.java    From calcite with Apache License 2.0 5 votes vote down vote up
public InterpreterImplementor(Compiler compiler,
    CalcitePrepare.SparkHandler spark,
    DataContext dataContext) {
  this.compiler = compiler;
  this.spark = spark;
  this.dataContext = dataContext;
}
 
Example 5
Source File: SparkHandlerImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Creates a SparkHandlerImpl, initializing on first call. Calcite-core calls
 * this via reflection. */
@SuppressWarnings("UnusedDeclaration")
public static CalcitePrepare.SparkHandler instance() {
  return Holder.INSTANCE;
}
 
Example 6
Source File: Schemas.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static CalcitePrepare.Context makeContext(
    final CalciteConnectionConfig connectionConfig,
    final JavaTypeFactory typeFactory,
    final DataContext dataContext,
    final CalciteSchema schema,
    final List<String> schemaPath, final List<String> objectPath_) {
  final ImmutableList<String> objectPath =
      objectPath_ == null ? null : ImmutableList.copyOf(objectPath_);
  return new CalcitePrepare.Context() {
    public JavaTypeFactory getTypeFactory() {
      return typeFactory;
    }

    public CalciteSchema getRootSchema() {
      return schema.root();
    }

    public CalciteSchema getMutableRootSchema() {
      return getRootSchema();
    }

    public List<String> getDefaultSchemaPath() {
      // schemaPath is usually null. If specified, it overrides schema
      // as the context within which the SQL is validated.
      if (schemaPath == null) {
        return schema.path(null);
      }
      return schemaPath;
    }

    public List<String> getObjectPath() {
      return objectPath;
    }

    public CalciteConnectionConfig config() {
      return connectionConfig;
    }

    public DataContext getDataContext() {
      return dataContext;
    }

    public RelRunner getRelRunner() {
      throw new UnsupportedOperationException();
    }

    public CalcitePrepare.SparkHandler spark() {
      final boolean enable = config().spark();
      return CalcitePrepare.Dummy.getSparkHandler(enable);
    }
  };
}