[ 
https://issues.apache.org/jira/browse/BEAM-4365?focusedWorklogId=110251&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-110251
 ]

ASF GitHub Bot logged work on BEAM-4365:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Jun/18 20:01
            Start Date: 08/Jun/18 20:01
    Worklog Time Spent: 10m 
      Work Description: akedin commented on a change in pull request #5433: 
[BEAM-4365] Make BeamSqlExpression for operators, use it for string operators
URL: https://github.com/apache/beam/pull/5433#discussion_r194166749
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/interpreter/operator/StringOperators.java
 ##########
 @@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.beam.sdk.extensions.sql.impl.interpreter.operator;
+
+import java.util.List;
+import org.apache.calcite.runtime.SqlFunctions;
+import org.apache.calcite.sql.fun.SqlTrimFunction;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/** String operator implementations. */
+public class StringOperators {
+
+  /** A {@link BeamSqlOperator} that returns a string. */
+  public interface StringOperator extends BeamSqlOperator {
+    default SqlTypeName getOutputType() {
+      return SqlTypeName.VARCHAR;
+    }
+  }
+
+  @FunctionalInterface
+  private interface StringUnaryOperator extends BeamSqlUnaryOperator {
+    default boolean accept(BeamSqlExpression arg) {
+      return SqlTypeName.CHAR_TYPES.contains(arg.getOutputType());
+    }
+
+    default SqlTypeName getOutputType() {
+      return SqlTypeName.VARCHAR;
+    }
+  }
+
+  public static final BeamSqlOperator CHAR_LENGTH =
+      (StringUnaryOperator)
+          (BeamSqlPrimitive arg) ->
+              BeamSqlPrimitive.of(SqlTypeName.INTEGER, 
SqlFunctions.charLength(arg.getString()));
+
+  public static final BeamSqlOperator UPPER =
+      (StringUnaryOperator)
+          (BeamSqlPrimitive arg) ->
+              BeamSqlPrimitive.of(SqlTypeName.VARCHAR, 
SqlFunctions.upper(arg.getString()));
+
+  public static final BeamSqlOperator LOWER =
+      (StringUnaryOperator)
+          (BeamSqlPrimitive arg) ->
+              BeamSqlPrimitive.of(SqlTypeName.VARCHAR, 
SqlFunctions.lower(arg.getString()));
+
+  /** {@code INITCAP}. */
+  public static final BeamSqlOperator INIT_CAP =
+      (StringUnaryOperator)
+          (BeamSqlPrimitive arg) ->
+              BeamSqlPrimitive.of(SqlTypeName.VARCHAR, 
SqlFunctions.initcap(arg.getString()));
 
 Review comment:
   Can these be put into maps? E.g.:
   
   ```
   UNARY_FUNCTIONS = ImmutableMap.<SqlOperator, Function<String, String>>of(
      SqlStdOperatorTable.INITCAP, SqlFunctions::initcap,
      ...
   );
   
   BINARY_FUNCTIONS = ImmutableMap.<SqlOperator, BiFunction<String, String, 
String>>of(
   
   ```

----------------------------------------------------------------
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: 110251)
    Time Spent: 1h 50m  (was: 1h 40m)

> SQL operator argument evaluation should have one place where it is managed
> --------------------------------------------------------------------------
>
>                 Key: BEAM-4365
>                 URL: https://issues.apache.org/jira/browse/BEAM-4365
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql
>            Reporter: Kenneth Knowles
>            Assignee: Kenneth Knowles
>            Priority: Major
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> The way Beam SQL is factored, each operator has to explicitly ask its 
> argument to be evaluated. This should be handled generically at a higher 
> level. Since the language is pure and terminating, it is fine for them to 
> vary, but given the simplicity of the expression language it makes sense to 
> use simple call-by-value.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to