You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/12/26 09:35:00 UTC

[GitHub] [calcite] LiShuMing opened a new pull request #1694: [CALCITE-2935] [CALCITE-3616] CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function

LiShuMing opened a new pull request #1694: [CALCITE-2935] [CALCITE-3616] CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694
 
 
   As [CALCITE-2935](https://issues.apache.org/jira/browse/CALCITE-2935)/[CALCITE-3616](https://issues.apache.org/jira/browse/CALCITE-3616)/[CALCITE-3617](https://issues.apache.org/jira/browse/CALCITE-3617) discussed, add support BOOL_AND/BOOL_OR aggregate function.
   
   Add unit tests in `SqlOperatorBaseTest` and `SqlValidatorTest`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361560821
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,54 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Instance fields --------------------------------------------------------
+
 
 Review comment:
   Remove this line ~

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361561976
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   Since `BOOL_AND` and `BOOL_OR` are alias of `max` `min`, the only reason we need this maybe the validation error reporting.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362186317
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   Thanks for @danny0405 's replies. Yep, you are right.  Updated as you said.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362142155
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   I've checked again. I think it's still better to keep this class/func just like `SqlMinMaxAggFunction`/`SqlAnyValueAggFunction` for this patch.
   
    In `AggregateUnionTransposeRule` or `Match` class, it's easier to use the specific `SqlAggFunction`, otherwise need change some origin codes.
   
    In `AggregateUnionTransposeRule`,  it use `Map<Class<? extends SqlAggFunction>, Boolean>` to define the specific SqlAggFunction type which may be replaced by a `SqlKind` sets later. However I think this maybe optimized by followed patches later?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] chunweilei commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
chunweilei commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362136526
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   Do we really need this class to create the function? Or just use `new SqlAggFunction(...)`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jinxing64 commented on issue #1694: [CALCITE-2935] [CALCITE-3616] CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
jinxing64 commented on issue #1694: [CALCITE-2935] [CALCITE-3616] CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#issuecomment-569026253
 
 
   The title missed a "[" before `CALCITE-3617`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361561244
 
 

 ##########
 File path: site/_docs/reference.md
 ##########
 @@ -1751,6 +1751,8 @@ and `LISTAGG`).
 | SUM( [ ALL &#124; DISTINCT ] numeric)         | Returns the sum of *numeric* across all input values
 | MAX( [ ALL &#124; DISTINCT ] value)           | Returns the maximum value of *value* across all input values
 | MIN( [ ALL &#124; DISTINCT ] value)           | Returns the minimum value of *value* across all input values
+| BOOL_AND(value)                               | Returns true if all *values* are true
+| BOOL_OR(value)                                | Returns true if at least one value of *value* is true
 
 Review comment:
   Here is my mistake. I checked [Redshift Document](https://docs.aws.amazon.com/redshift/latest/dg/r_BOOL_OR.html), `[DISTINCT | ALL] ` should be supported.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361561256
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,54 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Instance fields --------------------------------------------------------
+
 
 Review comment:
   OK

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362159799
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
 
 Review comment:
   Shall we explain here that how `BOOL_AND/BOOL_OR` works ? and how it's analogous to `MIN/MAX` ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362160755
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
 ##########
 @@ -8724,6 +8724,64 @@ protected void checkAggType(SqlTester tester, String expr, String type) {
         0d);
   }
 
+  @Test public void testBoolAndFunc() {
+    tester.setFor(SqlStdOperatorTable.BOOL_AND, VM_EXPAND);
+
+    tester.checkFails(
+        "bool_and(^*^)",
+        "Unknown identifier '\\*'",
+        false);
+    tester.checkType("bool_and(true)", "BOOLEAN");
+    tester.checkFails("^bool_and(1)^",
+        "Cannot apply 'BOOL_AND' to arguments of type 'BOOL_AND\\(<INTEGER>\\)'\\. "
+            + "Supported form\\(s\\): 'BOOL_AND\\(<BOOLEAN>\\)'",
+        false);
+    tester.checkFails(
+        "^bool_and()^",
+        "Invalid number of arguments to function 'BOOL_AND'. Was expecting 1 arguments",
+        false);
+    tester.checkFails(
+        "^bool_and(true, true)^",
+        "Invalid number of arguments to function 'BOOL_AND'. Was expecting 1 arguments",
+        false);
+
+    final String[] values1 = {"true", "true", "null"};
 
 Review comment:
   Shall we add a test of `values = {null}` ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362181525
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   I think @chunweilei is right, this class is not necessary, the `SqlMinMaxAggFunction` is needed because we need to customize the type inference, but for this function, it is simple.
   
   I haven't figured out why `AggregateUnionTransposeRule` is affected if we use `SqlAggFunction` directly, it would output the wrong results ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362137477
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   Good Idea. Let me fix it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jinxing64 commented on issue #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
jinxing64 commented on issue #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#issuecomment-569878591
 
 
   Not related to this PR --
   Doc of [1] seems a typo, should it be `min/max` ? If so, shall we resolve the typo in this PR ?
   
   [1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java#L41

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361905362
 
 

 ##########
 File path: site/_docs/reference.md
 ##########
 @@ -1751,6 +1751,8 @@ and `LISTAGG`).
 | SUM( [ ALL &#124; DISTINCT ] numeric)         | Returns the sum of *numeric* across all input values
 | MAX( [ ALL &#124; DISTINCT ] value)           | Returns the maximum value of *value* across all input values
 | MIN( [ ALL &#124; DISTINCT ] value)           | Returns the minimum value of *value* across all input values
+| BOOL_AND( [ ALL &#124; DISTINCT ] value)      | Returns true if all *values* are true
+| BOOL_OR( [ ALL &#124; DISTINCT ] value)       | Returns true if at least one value of *value* is true
 | ANY_VALUE( [ ALL &#124; DISTINCT ] value)     | Returns one of the values of *value* across all input values; this is NOT specified in the SQL standard
 
 Review comment:
   of *value* -> of *values*

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] amaliujia commented on a change in pull request #1694: [CALCITE-2935] [CALCITE-3616] [CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
amaliujia commented on a change in pull request #1694: [CALCITE-2935] [CALCITE-3616] [CALCITE-3617] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361542724
 
 

 ##########
 File path: site/_docs/reference.md
 ##########
 @@ -1751,6 +1751,8 @@ and `LISTAGG`).
 | SUM( [ ALL &#124; DISTINCT ] numeric)         | Returns the sum of *numeric* across all input values
 | MAX( [ ALL &#124; DISTINCT ] value)           | Returns the maximum value of *value* across all input values
 | MIN( [ ALL &#124; DISTINCT ] value)           | Returns the minimum value of *value* across all input values
+| BOOL_AND(value)                               | Returns true if all *values* are true
+| BOOL_OR(value)                                | Returns true if at least one value of *value* is true
 
 Review comment:
   Does BOOL_AND/OR support `[DISTINCT]` keyword?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361885819
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.util.Optionality;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions.
+ */
+public class SqlBoolAggFunction extends SqlAggFunction {
+
+  //~ Constructors -----------------------------------------------------------
+
+  /** Creates a SqlBoolAggFunction. */
+  public SqlBoolAggFunction(SqlKind kind) {
+    super(kind.name(),
+        null,
+        kind,
+        ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
+        null,
+        OperandTypes.BOOLEAN,
+        SqlFunctionCategory.SYSTEM,
+        false,
+        false,
+        Optionality.FORBIDDEN);
+    Preconditions.checkArgument(kind == SqlKind.BOOL_AND
+        || kind == SqlKind.BOOL_OR);
 
 Review comment:
   Yep. And Input type checking.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
jinxing64 commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362158878
 
 

 ##########
 File path: site/_docs/reference.md
 ##########
 @@ -1751,6 +1751,8 @@ and `LISTAGG`).
 | SUM( [ ALL &#124; DISTINCT ] numeric)         | Returns the sum of *numeric* across all input values
 | MAX( [ ALL &#124; DISTINCT ] value)           | Returns the maximum value of *value* across all input values
 | MIN( [ ALL &#124; DISTINCT ] value)           | Returns the minimum value of *value* across all input values
+| BOOL_AND( [ ALL &#124; DISTINCT ] value)      | Returns true if all *values* are true
+| BOOL_OR( [ ALL &#124; DISTINCT ] value)       | Returns true if at least one value of *value* is true
 | ANY_VALUE( [ ALL &#124; DISTINCT ] value)     | Returns one of the values of *value* across all input values; this is NOT specified in the SQL standard
 
 Review comment:
   Shall we use the word of value consistent with `MAX` & `MIN` ? -- it's a param of the function.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] hsyuan commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
hsyuan commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r361545436
 
 

 ##########
 File path: site/_docs/reference.md
 ##########
 @@ -1751,6 +1751,8 @@ and `LISTAGG`).
 | SUM( [ ALL &#124; DISTINCT ] numeric)         | Returns the sum of *numeric* across all input values
 | MAX( [ ALL &#124; DISTINCT ] value)           | Returns the maximum value of *value* across all input values
 | MIN( [ ALL &#124; DISTINCT ] value)           | Returns the minimum value of *value* across all input values
+| BOOL_AND(value)                               | Returns true if all *values* are true
+| BOOL_OR(value)                                | Returns true if at least one value of *value* is true
 
 Review comment:
   Yes, it should be ignored.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function

Posted by GitBox <gi...@apache.org>.
LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function
URL: https://github.com/apache/calcite/pull/1694#discussion_r362186416
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
 ##########
 @@ -8724,6 +8724,64 @@ protected void checkAggType(SqlTester tester, String expr, String type) {
         0d);
   }
 
+  @Test public void testBoolAndFunc() {
+    tester.setFor(SqlStdOperatorTable.BOOL_AND, VM_EXPAND);
+
+    tester.checkFails(
+        "bool_and(^*^)",
+        "Unknown identifier '\\*'",
+        false);
+    tester.checkType("bool_and(true)", "BOOLEAN");
+    tester.checkFails("^bool_and(1)^",
+        "Cannot apply 'BOOL_AND' to arguments of type 'BOOL_AND\\(<INTEGER>\\)'\\. "
+            + "Supported form\\(s\\): 'BOOL_AND\\(<BOOLEAN>\\)'",
+        false);
+    tester.checkFails(
+        "^bool_and()^",
+        "Invalid number of arguments to function 'BOOL_AND'. Was expecting 1 arguments",
+        false);
+    tester.checkFails(
+        "^bool_and(true, true)^",
+        "Invalid number of arguments to function 'BOOL_AND'. Was expecting 1 arguments",
+        false);
+
+    final String[] values1 = {"true", "true", "null"};
 
 Review comment:
   Thanks @jinxing64 's replies. Updated as you reviewed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services