You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by twalthr <gi...@git.apache.org> on 2016/02/20 21:53:51 UTC

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

GitHub user twalthr opened a pull request:

    https://github.com/apache/flink/pull/1679

    [FLINK-3226] Translation of scalar function substring()

    This PR implements the scalar function `substring()` for the Table API on Calcite. Additionally, it already contains preparations for more built-in SQL functions. I implemented test utils for scalar functions `ScalarFunctionsTest` and added a similar concept to Calcites `CallImplementor` named `CallGenerator`.
    
    For now, I kept the `Substring` expression node, but I would like to remove it and use a generic `Call` expression. I think we don't need a case class for every operator. What do you think?

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/twalthr/flink AdvancedOperators

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/1679.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1679
    
----
commit 0106e4723f38ab533bf15c909b98299e27530b2a
Author: twalthr <tw...@apache.org>
Date:   2016-02-20T20:41:44Z

    [FLINK-3226] Translation of scalar function substring()

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53905238
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/StringExpressionsITCase.java ---
    @@ -40,46 +40,6 @@ public StringExpressionsITCase(TestExecutionMode mode) {
     		super(mode);
     	}
     
    -	@Test(expected = CodeGenException.class)
    --- End diff --
    
    No, the `ScalarFunctionsTest` does not test end-to-end. I don't think this is necessary for scalar functions, because they don't affect optimization/plan translation. When we will have more functions (e.g. 40 of them), we would have 40 end-to-end tests just implementing a MapFunction and evaluating an expression. That's why I implemented the `ExpressionEvaluator`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53763449
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/StringExpressionsITCase.java ---
    @@ -40,46 +40,6 @@ public StringExpressionsITCase(TestExecutionMode mode) {
     		super(mode);
     	}
     
    -	@Test(expected = CodeGenException.class)
    --- End diff --
    
    Why did you remove these tests? The `ScalarFunctionsTest` does not test the feature end-to-end, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53751120
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala ---
    @@ -702,12 +704,17 @@ class CodeGenerator(
             requireBoolean(operand)
             generateNot(nullCheck, operand)
     
    +      // casting
           case CAST =>
             val operand = operands.head
             generateCast(nullCheck, operand, resultType)
     
    -      case call@_ =>
    --- End diff --
    
    Add the all case to the end to get a good error message.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr closed the pull request at:

    https://github.com/apache/flink/pull/1679


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:

    https://github.com/apache/flink/pull/1679#issuecomment-187648227
  
    I had only a few minor comments. Looks mostly good.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on the pull request:

    https://github.com/apache/flink/pull/1679#issuecomment-188219011
  
    @fhueske build succeeded


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53910352
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/StringExpressionsITCase.java ---
    @@ -40,46 +40,6 @@ public StringExpressionsITCase(TestExecutionMode mode) {
     		super(mode);
     	}
     
    -	@Test(expected = CodeGenException.class)
    --- End diff --
    
    Yes, you are right, testing at least one function end-to-end makes sense. I will add them again.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53906027
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/StringExpressionsITCase.java ---
    @@ -40,46 +40,6 @@ public StringExpressionsITCase(TestExecutionMode mode) {
     		super(mode);
     	}
     
    -	@Test(expected = CodeGenException.class)
    --- End diff --
    
    Agreed, we should not have end-to-end tests for all scalar functions. But it would be good to tests at least some representative functions, IMO.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53763082
  
    --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/test/ScalarFunctionsTest.scala ---
    @@ -0,0 +1,96 @@
    +/*
    + * 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.flink.api.table.test
    +
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
    +import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.api.scala.table._
    +import org.apache.flink.api.table.Row
    +import org.apache.flink.api.table.expressions.Expression
    +import org.apache.flink.api.table.parser.ExpressionParser
    +import org.apache.flink.api.table.test.utils.ExpressionEvaluator
    +import org.apache.flink.api.table.typeinfo.RowTypeInfo
    +import org.junit.Assert.assertEquals
    +import org.junit.Test
    +
    +class ScalarFunctionsTest {
    +
    +  @Test
    +  def testSubstring(): Unit = {
    +    testFunction(
    +      'f0.substring(2),
    +      "f0.substring(2)",
    +      "SUBSTRING(f0, 2)",
    +      "his is a test String.")
    +
    +    testFunction(
    +      'f0.substring(2, 5),
    +      "f0.substring(2, 5)",
    +      "SUBSTRING(f0, 2, 5)",
    +      "his i")
    +
    +    testFunction(
    +      'f0.substring(1, 'f7),
    +      "f0.substring(1, f7)",
    +      "SUBSTRING(f0, 1, f7)",
    +      "Thi")
    +  }
    +
    +  // ----------------------------------------------------------------------------------------------
    +
    +  def testFunction(
    +      expr: Expression,
    +      exprString: String,
    +      sqlExpr: String,
    +      expected: String): Unit = {
    +    val testData = new Row(8)
    +    testData.setField(0, "This is a test String.")
    +    testData.setField(1, true)
    +    testData.setField(2, 42.toByte)
    +    testData.setField(3, 43.toShort)
    +    testData.setField(4, 44.toLong)
    +    testData.setField(5, 4.5.toFloat)
    +    testData.setField(6, 4.6)
    +    testData.setField(7, 3)
    +
    +    val typeInfo = new RowTypeInfo(Seq(
    +      STRING_TYPE_INFO,
    +      BOOLEAN_TYPE_INFO,
    +      BYTE_TYPE_INFO,
    +      SHORT_TYPE_INFO,
    +      LONG_TYPE_INFO,
    +      FLOAT_TYPE_INFO,
    +      DOUBLE_TYPE_INFO,
    +      INT_TYPE_INFO)).asInstanceOf[TypeInformation[Any]]
    +
    +    val exprResult = ExpressionEvaluator.evaluate(testData, typeInfo, expr)
    +    assertEquals(expected, exprResult)
    +
    +    val exprStringResult = ExpressionEvaluator.evaluate(
    +      testData,
    +      typeInfo,
    +      ExpressionParser.parseExpression(exprString))
    +    assertEquals(expected, exprStringResult)
    +
    +    // TODO test SQL expression
    --- End diff --
    
    Resolve TODO?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:

    https://github.com/apache/flink/pull/1679#issuecomment-188669681
  
    Thanks for the update. Looks good to merge


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on the pull request:

    https://github.com/apache/flink/pull/1679#issuecomment-188655499
  
    If there are no objections, I would like to merge this later.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53763441
  
    --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/table/test/StringExpressionsITCase.scala ---
    @@ -18,42 +18,20 @@
     
     package org.apache.flink.api.scala.table.test
     
    -import org.apache.flink.api.table.{Row, ExpressionException}
     import org.apache.flink.api.scala._
     import org.apache.flink.api.scala.table._
    -import org.apache.flink.test.util.{TestBaseUtils, MultipleProgramsTestBase}
    +import org.apache.flink.api.table.Row
     import org.apache.flink.test.util.MultipleProgramsTestBase.TestExecutionMode
    +import org.apache.flink.test.util.{MultipleProgramsTestBase, TestBaseUtils}
     import org.junit._
     import org.junit.runner.RunWith
     import org.junit.runners.Parameterized
    +
     import scala.collection.JavaConverters._
    -import org.apache.flink.api.table.codegen.CodeGenException
     
     @RunWith(classOf[Parameterized])
     class StringExpressionsITCase(mode: TestExecutionMode) extends MultipleProgramsTestBase(mode) {
     
    -  @Test(expected = classOf[CodeGenException])
    --- End diff --
    
    Why did you remove these tests? The `ScalarFunctionsTest` does not test the feature end-to-end, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3226] Translation of scalar function su...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1679#discussion_r53905333
  
    --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/test/ScalarFunctionsTest.scala ---
    @@ -0,0 +1,96 @@
    +/*
    + * 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.flink.api.table.test
    +
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
    +import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.api.scala.table._
    +import org.apache.flink.api.table.Row
    +import org.apache.flink.api.table.expressions.Expression
    +import org.apache.flink.api.table.parser.ExpressionParser
    +import org.apache.flink.api.table.test.utils.ExpressionEvaluator
    +import org.apache.flink.api.table.typeinfo.RowTypeInfo
    +import org.junit.Assert.assertEquals
    +import org.junit.Test
    +
    +class ScalarFunctionsTest {
    +
    +  @Test
    +  def testSubstring(): Unit = {
    +    testFunction(
    +      'f0.substring(2),
    +      "f0.substring(2)",
    +      "SUBSTRING(f0, 2)",
    +      "his is a test String.")
    +
    +    testFunction(
    +      'f0.substring(2, 5),
    +      "f0.substring(2, 5)",
    +      "SUBSTRING(f0, 2, 5)",
    +      "his i")
    +
    +    testFunction(
    +      'f0.substring(1, 'f7),
    +      "f0.substring(1, f7)",
    +      "SUBSTRING(f0, 1, f7)",
    +      "Thi")
    +  }
    +
    +  // ----------------------------------------------------------------------------------------------
    +
    +  def testFunction(
    +      expr: Expression,
    +      exprString: String,
    +      sqlExpr: String,
    +      expected: String): Unit = {
    +    val testData = new Row(8)
    +    testData.setField(0, "This is a test String.")
    +    testData.setField(1, true)
    +    testData.setField(2, 42.toByte)
    +    testData.setField(3, 43.toShort)
    +    testData.setField(4, 44.toLong)
    +    testData.setField(5, 4.5.toFloat)
    +    testData.setField(6, 4.6)
    +    testData.setField(7, 3)
    +
    +    val typeInfo = new RowTypeInfo(Seq(
    +      STRING_TYPE_INFO,
    +      BOOLEAN_TYPE_INFO,
    +      BYTE_TYPE_INFO,
    +      SHORT_TYPE_INFO,
    +      LONG_TYPE_INFO,
    +      FLOAT_TYPE_INFO,
    +      DOUBLE_TYPE_INFO,
    +      INT_TYPE_INFO)).asInstanceOf[TypeInformation[Any]]
    +
    +    val exprResult = ExpressionEvaluator.evaluate(testData, typeInfo, expr)
    +    assertEquals(expected, exprResult)
    +
    +    val exprStringResult = ExpressionEvaluator.evaluate(
    +      testData,
    +      typeInfo,
    +      ExpressionParser.parseExpression(exprString))
    +    assertEquals(expected, exprStringResult)
    +
    +    // TODO test SQL expression
    --- End diff --
    
    Once we have a SQL parser ready, I will resolve this TODO ;-)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---