[
https://issues.apache.org/jira/browse/BEAM-5112?focusedWorklogId=178753&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-178753
]
ASF GitHub Bot logged work on BEAM-5112:
----------------------------------------
Author: ASF GitHub Bot
Created on: 26/Dec/18 19:42
Start Date: 26/Dec/18 19:42
Worklog Time Spent: 10m
Work Description: akedin commented on pull request #6417: [BEAM-5112] Use
Calcite codegen to implement BeamCalcRel
URL: https://github.com/apache/beam/pull/6417#discussion_r244038441
##########
File path:
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java
##########
@@ -96,43 +224,243 @@ public boolean isInputSortRelAndLimitOnly() {
/** {@code CalcFn} is the executor for a {@link BeamCalcRel} step. */
private static class CalcFn extends DoFn<Row, Row> {
- private BeamSqlExpressionExecutor executor;
- private Schema outputSchema;
+ private final String processElementBlock;
+ private final Schema outputSchema;
+ private transient @Nullable ScriptEvaluator se = null;
- public CalcFn(BeamSqlExpressionExecutor executor, Schema outputSchema) {
- super();
- this.executor = executor;
+ public CalcFn(String processElementBlock, Schema outputSchema) {
+ this.processElementBlock = processElementBlock;
this.outputSchema = outputSchema;
}
+ ScriptEvaluator compile() {
+ ScriptEvaluator se = new ScriptEvaluator();
+ se.setParameters(
+ new String[] {outputSchemaParam.name, processContextParam.name,
DataContext.ROOT.name},
+ new Class[] {
+ (Class) outputSchemaParam.getType(),
+ (Class) processContextParam.getType(),
+ (Class) DataContext.ROOT.getType()
+ });
+ try {
+ se.cook(processElementBlock);
+ } catch (CompileException e) {
+ throw new RuntimeException("Could not compile CalcFn: " +
processElementBlock, e);
+ }
+ return se;
+ }
+
@Setup
public void setup() {
- executor.prepare();
+ this.se = compile();
}
@ProcessElement
public void processElement(ProcessContext c) {
- Row inputRow = c.element();
- @Nullable
- List<Object> rawResultValues =
- executor.execute(inputRow, null,
BeamSqlExpressionEnvironments.forRow(inputRow, null));
-
- if (rawResultValues != null) {
- List<Object> castResultValues =
- IntStream.range(0, outputSchema.getFieldCount())
- .mapToObj(i -> castField(rawResultValues, i))
- .collect(toList());
-
c.output(Row.withSchema(outputSchema).addValues(castResultValues).build());
+ assert se != null;
+ try {
+ se.evaluate(new Object[] {outputSchema, c, CONTEXT_INSTANCE});
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(
+ "CalcFn failed to evaluate: " + processElementBlock, e.getCause());
+ }
+ }
+ }
+
+ private static final Map<TypeName, Type> rawTypeMap =
+ ImmutableMap.<TypeName, Type>builder()
+ .put(TypeName.BYTE, Byte.class)
+ .put(TypeName.INT16, Short.class)
+ .put(TypeName.INT32, Integer.class)
+ .put(TypeName.INT64, Long.class)
+ .put(TypeName.FLOAT, Float.class)
+ .put(TypeName.DOUBLE, Double.class)
+ .build();
+
+ private Expression castOutput(Expression value, FieldType toType) {
+ if (value.getType() == Object.class) {
Review comment:
Is this possible to get an expression with `Object` type? Would it be safer
to throw here to avoid breaking something in our schema logic?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 178753)
Time Spent: 3h (was: 2h 50m)
> Investigate if Calcite can generate functions that we need
> ----------------------------------------------------------
>
> Key: BEAM-5112
> URL: https://issues.apache.org/jira/browse/BEAM-5112
> Project: Beam
> Issue Type: Sub-task
> Components: dsl-sql
> Reporter: Rui Wang
> Assignee: Andrew Pilloud
> Priority: Major
> Time Spent: 3h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)