[
https://issues.apache.org/jira/browse/BEAM-5112?focusedWorklogId=179567&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-179567
]
ASF GitHub Bot logged work on BEAM-5112:
----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Dec/18 20:54
Start Date: 28/Dec/18 20:54
Worklog Time Spent: 10m
Work Description: apilloud commented on pull request #6417: [BEAM-5112]
Use Calcite codegen to implement BeamCalcRel
URL: https://github.com/apache/beam/pull/6417#discussion_r244406033
##########
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) {
Review comment:
It is never used outside of this class, I think leaving it here makes this
code easier to understand. If we have a second use case for it we can move it
out to `CalciteUtils`.
----------------------------------------------------------------
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: 179567)
Time Spent: 4h (was: 3h 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: 4h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)