[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread asfgit
Github user asfgit closed the pull request at:

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


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86138204
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/ScalarFunctionsTest.scala
 ---
@@ -377,11 +378,79 @@ class ScalarFunctionsTest extends ExpressionTestBase {
   "f4.power(f5)",
   "POWER(f4, f5)",
   math.pow(44.toLong, 4.5.toFloat).toString)
+
+// f5: float
+testAllApis('f5.power('f5), "f5.power(f5)", "power(f5, f5)", 
math.pow(4.5F, 4.5F).toString)
+testAllApis('f5.power('f6), "f5.power(f6)", "power(f5, f6)", 
math.pow(4.5F, 4.6D).toString)
+testAllApis('f5.power('f7), "f5.power(f7)", "power(f5, f7)", 
math.pow(4.5F, 3).toString)
+testAllApis('f5.power('f4), "f5.power(f4)", "power(f5, f4)", 
math.pow(4.5F, 44L).toString)
+
+// f22: bigDecimal
+// TODO delete casting in SQL when CALCITE-1467 is fixed
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f4),
+  "f22.cast(DOUBLE).power(f5)",
+  "power(CAST(f22 AS DOUBLE), f5)",
+  "1.0")
+
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f5),
+  "f22.cast(DOUBLE).power(f6)",
--- End diff --

Shouldn't this be `"f22.cast(DOUBLE).power(f5)"`
Same for SQL expression.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86138673
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/ScalarFunctionsTest.scala
 ---
@@ -377,11 +378,79 @@ class ScalarFunctionsTest extends ExpressionTestBase {
   "f4.power(f5)",
   "POWER(f4, f5)",
   math.pow(44.toLong, 4.5.toFloat).toString)
+
+// f5: float
+testAllApis('f5.power('f5), "f5.power(f5)", "power(f5, f5)", 
math.pow(4.5F, 4.5F).toString)
--- End diff --

Please break statements to be consistent with other tests in this file.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86138263
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/ScalarFunctionsTest.scala
 ---
@@ -377,11 +378,79 @@ class ScalarFunctionsTest extends ExpressionTestBase {
   "f4.power(f5)",
   "POWER(f4, f5)",
   math.pow(44.toLong, 4.5.toFloat).toString)
+
+// f5: float
+testAllApis('f5.power('f5), "f5.power(f5)", "power(f5, f5)", 
math.pow(4.5F, 4.5F).toString)
+testAllApis('f5.power('f6), "f5.power(f6)", "power(f5, f6)", 
math.pow(4.5F, 4.6D).toString)
+testAllApis('f5.power('f7), "f5.power(f7)", "power(f5, f7)", 
math.pow(4.5F, 3).toString)
+testAllApis('f5.power('f4), "f5.power(f4)", "power(f5, f4)", 
math.pow(4.5F, 44L).toString)
+
+// f22: bigDecimal
+// TODO delete casting in SQL when CALCITE-1467 is fixed
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f4),
+  "f22.cast(DOUBLE).power(f5)",
+  "power(CAST(f22 AS DOUBLE), f5)",
+  "1.0")
+
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f5),
+  "f22.cast(DOUBLE).power(f6)",
+  "power(CAST(f22 AS DOUBLE), f6)",
+  "1.0")
+
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f7),
+  "f22.cast(DOUBLE).power(f7)",
+  "power(CAST(f22 AS DOUBLE), f7)",
+  "1.0")
+
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f4),
--- End diff --

Same as above?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86138100
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/ScalarFunctionsTest.scala
 ---
@@ -377,11 +378,79 @@ class ScalarFunctionsTest extends ExpressionTestBase {
   "f4.power(f5)",
   "POWER(f4, f5)",
   math.pow(44.toLong, 4.5.toFloat).toString)
+
+// f5: float
+testAllApis('f5.power('f5), "f5.power(f5)", "power(f5, f5)", 
math.pow(4.5F, 4.5F).toString)
+testAllApis('f5.power('f6), "f5.power(f6)", "power(f5, f6)", 
math.pow(4.5F, 4.6D).toString)
+testAllApis('f5.power('f7), "f5.power(f7)", "power(f5, f7)", 
math.pow(4.5F, 3).toString)
+testAllApis('f5.power('f4), "f5.power(f4)", "power(f5, f4)", 
math.pow(4.5F, 44L).toString)
+
+// f22: bigDecimal
+// TODO delete casting in SQL when CALCITE-1467 is fixed
+testAllApis(
+  'f22.cast(Types.DOUBLE).power('f4),
+  "f22.cast(DOUBLE).power(f5)",
--- End diff --

Shouldn't this be `"f22.cast(DOUBLE).power(f4)"`?
Same for SQL expression.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86127428
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/ScalarFunctionsTest.scala
 ---
@@ -377,11 +378,79 @@ class ScalarFunctionsTest extends ExpressionTestBase {
   "f4.power(f5)",
   "POWER(f4, f5)",
   math.pow(44.toLong, 4.5.toFloat).toString)
+
+// f5: float
+testAllApis('f5.power('f5), "f5.power(f5)", "power(f5, f5)", 
math.pow(4.5F, 4.5F).toString)
+testAllApis('f5.power('f6), "f5.power(f6)", "power(f5, f6)", 
math.pow(4.5F, 4.6D).toString)
+testAllApis('f5.power('f7), "f5.power(f7)", "power(f5, f7)", 
math.pow(4.5F, 3).toString)
+testAllApis('f5.power('f4), "f5.power(f4)", "power(f5, f4)", 
math.pow(4.5F, 44L).toString)
+
+// f15: bigDecimal
--- End diff --

minor f15->f22?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86111954
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

What if we define a `MathFunctions` class and a companion object?

```
class MathFunctions { }

object MathFunctions {
  def power(...) 
}
```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread tonycox
Github user tonycox commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86108721
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

Why I didn't write `power` function in scala class.

I plunged into a problem with static access to method. I tried rewrite 
`MathFunctions.java` into Scala object https://goo.gl/rmLy8f . 
In BuiltInMethods we cannot to use `classOf[]` with scala `object`. So I 
used `getClass()`
Test throws [exception](http://pastebin.com/fLNr4CfX) 
because `getClass()` doesn't return `MathFunctions` itself, it returns 
`MathFunctions$` http://pastebin.com/LiZk45Fe 
**But** there is a solving :)
```
val POWER_DEC =

Types.lookupMethod(Class.forName(MathFunctions.getClass.getCanonicalName.dropRight(1)),
"power", classOf[Double], classOf[JBigDecimal])
```
I prefer java approach, what do you think @wuchong @fhueske ?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread tonycox
Github user tonycox commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86090398
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

i just implemented it into BuiltInMethods to see 
https://github.com/tonycox/flink/blob/4ebfd81e04d94161827f7bd55ee1146eedafeeb0/flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/calls/BuiltInMethods.scala
 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86089087
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

Scala handles `static` methods a bit differently than Java. Did you try to 
implement `MathFunctions` as a Scala object? See the paragraph on "Scala’s 
Sort-of Statics"  in this tutorial: 
http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-02 Thread tonycox
Github user tonycox commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86081029
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

We can't call Scala from generated Java code because of Calcit's compilation


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-11-01 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r86061549
  
--- Diff: 
flink-libraries/flink-table/src/main/java/org/apache/flink/api/table/functions/utils/MathFunctions.java
 ---
@@ -0,0 +1,29 @@
+/*
+ * 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.functions.utils;
+
+import java.math.BigDecimal;
+
+public class MathFunctions {
+
+   public static double power(double a, BigDecimal b) {
+   return Math.pow(a, b.doubleValue());
+   }
+
+}
--- End diff --

I would like to translate this class into Scala object to keep 
`flink-table` module pure Scala. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-31 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85732909
  
--- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/calls/ScalarFunctions.scala
 ---
@@ -153,17 +153,42 @@ object ScalarFunctions {
 DOUBLE_TYPE_INFO,
 BuiltInMethods.EXP)
 
+  // POWER
   addSqlFunctionMethod(
 POWER,
 Seq(DOUBLE_TYPE_INFO, DOUBLE_TYPE_INFO),
 DOUBLE_TYPE_INFO,
 BuiltInMethods.POWER)
 
-  addSqlFunctionMethod(
+  addSqlFunction(
 POWER,
 Seq(DOUBLE_TYPE_INFO, BIG_DEC_TYPE_INFO),
-DOUBLE_TYPE_INFO,
-BuiltInMethods.POWER_DEC)
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(FLOAT_TYPE_INFO, FLOAT_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(FLOAT_TYPE_INFO, BIG_DEC_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
--- End diff --

The same as above. Can be removed.



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-31 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85732797
  
--- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/calls/PowerCallGen.scala
 ---
@@ -0,0 +1,51 @@
+/*
+ * 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.codegen.calls
+
+import java.lang.reflect.Method
+
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.api.table.codegen.CodeGenUtils._
+import org.apache.flink.api.table.codegen.calls.CallGenerator._
+import org.apache.flink.api.table.codegen.{CodeGenerator, 
GeneratedExpression}
+
+class PowerCallGen(returnType: TypeInformation[_], method: Method) extends 
CallGenerator {
+
+  override def generate(
+codeGenerator: CodeGenerator,
+operands: Seq[GeneratedExpression])
+  : GeneratedExpression = {
+
+val castedOperands = operands.map { x =>
+  x.resultType match {
+case FLOAT_TYPE_INFO | BIG_DEC_TYPE_INFO =>
--- End diff --

Unnecessary to cast Float, we only need to cast BigDecimal here. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-31 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85732582
  
--- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/calls/ScalarFunctions.scala
 ---
@@ -153,17 +153,42 @@ object ScalarFunctions {
 DOUBLE_TYPE_INFO,
 BuiltInMethods.EXP)
 
+  // POWER
   addSqlFunctionMethod(
 POWER,
 Seq(DOUBLE_TYPE_INFO, DOUBLE_TYPE_INFO),
 DOUBLE_TYPE_INFO,
 BuiltInMethods.POWER)
 
-  addSqlFunctionMethod(
+  addSqlFunction(
 POWER,
 Seq(DOUBLE_TYPE_INFO, BIG_DEC_TYPE_INFO),
-DOUBLE_TYPE_INFO,
-BuiltInMethods.POWER_DEC)
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(FLOAT_TYPE_INFO, FLOAT_TYPE_INFO),
--- End diff --

Parameters  `(float, float)` will automatic choose `power(double, double)` 
to call. So there is no need to add this one.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-31 Thread wuchong
Github user wuchong commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85732685
  
--- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/calls/ScalarFunctions.scala
 ---
@@ -153,17 +153,42 @@ object ScalarFunctions {
 DOUBLE_TYPE_INFO,
 BuiltInMethods.EXP)
 
+  // POWER
   addSqlFunctionMethod(
 POWER,
 Seq(DOUBLE_TYPE_INFO, DOUBLE_TYPE_INFO),
 DOUBLE_TYPE_INFO,
 BuiltInMethods.POWER)
 
-  addSqlFunctionMethod(
+  addSqlFunction(
 POWER,
 Seq(DOUBLE_TYPE_INFO, BIG_DEC_TYPE_INFO),
-DOUBLE_TYPE_INFO,
-BuiltInMethods.POWER_DEC)
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(FLOAT_TYPE_INFO, FLOAT_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(FLOAT_TYPE_INFO, BIG_DEC_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(BIG_DEC_TYPE_INFO, BIG_DEC_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
+
+  addSqlFunction(
+POWER,
+Seq(BIG_DEC_TYPE_INFO, FLOAT_TYPE_INFO),
+new PowerCallGen(DOUBLE_TYPE_INFO, BuiltInMethods.POWER))
--- End diff --

The same as above. Can be removed.



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-28 Thread tonycox
GitHub user tonycox reopened a pull request:

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

[FLINK-4743] The sqrt/power function not accept the real data types.

Add supporting of variety types on "power" function. Add casting for Float 
and BigDecimal.

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

$ git pull https://github.com/tonycox/flink FLINK-4743

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

https://github.com/apache/flink/pull/2686.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 #2686


commit e5cfd1106b3c69f599149b56eee2ede7936e1e63
Author: anton_solo...@epam.com 
Date:   2016-10-17T07:44:12Z

[FLINK-4743] Add supporting of variety types on "power" function. Add 
casting for Float and BigDecimal.




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-28 Thread tonycox
Github user tonycox closed the pull request at:

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


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-28 Thread tonycox
Github user tonycox commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85514611
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/PowerExpressionTest.scala
 ---
@@ -0,0 +1,149 @@
+/*
+ * 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.expressions
+
+import java.lang.{Double => JDouble, Float => JFloat, Long => JLong, 
Integer => JInteger}
+import java.math.{BigDecimal => JBigDecimal}
+
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.api.table.expressions.utils.ExpressionTestBase
+import org.apache.flink.api.table.typeutils.RowTypeInfo
+import org.apache.flink.api.table.{Row, Types}
+import org.junit.Test
+
+class PowerExpressionTest extends ExpressionTestBase {
+
+  override def testData = {
+val testData = new Row(5)
+testData.setField(0, 100.0f: JFloat)
+testData.setField(1, 100.0: JDouble)
+testData.setField(2, 100L: JLong)
+testData.setField(3, 100: JInteger)
+testData.setField(4, new JBigDecimal(100): JBigDecimal)
+testData
+  }
+
+  override def typeInfo = {
+new RowTypeInfo(Seq(
+  Types.FLOAT,
+  Types.DOUBLE,
+  Types.LONG,
+  Types.INT,
+  Types.DECIMAL)
+).asInstanceOf[TypeInformation[Any]]
+  }
+
+  @Test
+  def testSqrtFloat(): Unit = {
+testSqlApi(
+  "SQRT(f0)",
+  "10.0")
+  }
+
+  @Test
+  def testSqrtDouble(): Unit = {
+testSqlApi(
--- End diff --

Yes, but i found out another bug. with this api 'f1.sqrt() and f1 is 
bigDecimal so test throws ValidationException. I wrote about it in dev mailing


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-26 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85218584
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/PowerExpressionTest.scala
 ---
@@ -0,0 +1,149 @@
+/*
+ * 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.expressions
+
+import java.lang.{Double => JDouble, Float => JFloat, Long => JLong, 
Integer => JInteger}
+import java.math.{BigDecimal => JBigDecimal}
+
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.api.table.expressions.utils.ExpressionTestBase
+import org.apache.flink.api.table.typeutils.RowTypeInfo
+import org.apache.flink.api.table.{Row, Types}
+import org.junit.Test
+
+class PowerExpressionTest extends ExpressionTestBase {
+
+  override def testData = {
+val testData = new Row(5)
+testData.setField(0, 100.0f: JFloat)
+testData.setField(1, 100.0: JDouble)
+testData.setField(2, 100L: JLong)
+testData.setField(3, 100: JInteger)
+testData.setField(4, new JBigDecimal(100): JBigDecimal)
+testData
+  }
+
+  override def typeInfo = {
+new RowTypeInfo(Seq(
+  Types.FLOAT,
+  Types.DOUBLE,
+  Types.LONG,
+  Types.INT,
+  Types.DECIMAL)
+).asInstanceOf[TypeInformation[Any]]
+  }
+
+  @Test
+  def testSqrtFloat(): Unit = {
+testSqlApi(
+  "SQRT(f0)",
+  "10.0")
+  }
+
+  @Test
+  def testSqrtDouble(): Unit = {
+testSqlApi(
--- End diff --

Can you extend the tests to all APIs (Table Scala, Table Java, SQL)?

```
testAllApis(
  'f1.sqrt(),
  "f1.sqrt",
  "SQRT(f1)",
  "10.0")
```

You need to add this import for the Scala Table API to work:

```
import org.apache.flink.api.scala.table._
```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-26 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/2686#discussion_r85217190
  
--- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/batch/sql/AggregationsITCase.scala
 ---
@@ -258,4 +258,22 @@ class AggregationsITCase(
 // must fail. grouping sets are not supported
 tEnv.sql(sqlQuery).toDataSet[Row]
   }
+
+  @Test
+  def testSqrtOfAggregatedSet(): Unit = {
--- End diff --

I think we do not need this ITCase. 
The `PowerExpressionTest` should cover all cases.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request #2686: [FLINK-4743] The sqrt/power function not accept th...

2016-10-24 Thread tonycox
GitHub user tonycox opened a pull request:

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

[FLINK-4743] The sqrt/power function not accept the real data types.

Add supporting of variety types on "power" function. Add casting for Float 
and BigDecimal.

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

$ git pull https://github.com/tonycox/flink FLINK-4743

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

https://github.com/apache/flink/pull/2686.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 #2686


commit e5cfd1106b3c69f599149b56eee2ede7936e1e63
Author: anton_solo...@epam.com 
Date:   2016-10-17T07:44:12Z

[FLINK-4743] Add supporting of variety types on "power" function. Add 
casting for Float and BigDecimal.




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---