[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2020-02-25 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r384155270
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1243,6 +1244,18 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
 IsNotNull(e)
   case SqlBaseParser.NULL =>
 IsNull(e)
+  case SqlBaseParser.TRUE => ctx.NOT match {
+case null => IsTrue(e)
 
 Review comment:
   Sorry for being late. +1 for that approach.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-30 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308826933
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ##
 @@ -840,3 +840,85 @@ case class GreaterThanOrEqual(left: Expression, right: 
Expression)
 
   protected override def nullSafeEval(input1: Any, input2: Any): Any = 
ordering.gteq(input1, input2)
 }
+
+trait BooleanTest extends UnaryExpression with Predicate with 
ExpectsInputTypes {
+
+  def boolValue: Boolean
+  def whenNull: Boolean
 
 Review comment:
   +1 for `boolValueWhenNull`. For the other, `boolValueForComparison` might be 
better instead of `boolValueForTest`?


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-29 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308523551
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -110,6 +110,13 @@ package object dsl {
 def isNull: Predicate = IsNull(expr)
 def isNotNull: Predicate = IsNotNull(expr)
 
+def isTrue: Predicate = IsTrue(expr)
+def isNotTrue: Predicate = IsNotTrue(expr)
+def isFalse: Predicate = IsFalse(expr)
+def isNotFalse: Predicate = IsNotFalse(expr)
+def isUnknown: Predicate = IsUnknown(expr)
+def isNotUnknown: Predicate = IsNotUnknown(expr)
 
 Review comment:
   No, @beliefer . You are confused with Scala DSL and SQL.
   This is `sql/catalyst/dsl` which providing Scala API. This is never ANSI SQL.
   SQL Standard doesn't have `def isNotUnknown`. :)


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-29 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308523551
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -110,6 +110,13 @@ package object dsl {
 def isNull: Predicate = IsNull(expr)
 def isNotNull: Predicate = IsNotNull(expr)
 
+def isTrue: Predicate = IsTrue(expr)
+def isNotTrue: Predicate = IsNotTrue(expr)
+def isFalse: Predicate = IsFalse(expr)
+def isNotFalse: Predicate = IsNotFalse(expr)
+def isUnknown: Predicate = IsUnknown(expr)
+def isNotUnknown: Predicate = IsNotUnknown(expr)
 
 Review comment:
   No, @beliefer . You are confused with Scala DSL and SQL.
   This is `sql/catalyst/dsl` which providing Scala API. This is never ANSI SQL.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-29 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308492305
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ##
 @@ -840,3 +840,81 @@ case class GreaterThanOrEqual(left: Expression, right: 
Expression)
 
   protected override def nullSafeEval(input1: Any, input2: Any): Any = 
ordering.gteq(input1, input2)
 }
+
+trait BooleanTest extends UnaryExpression with Predicate with 
ExpectsInputTypes {
+
+  def boolValue: Boolean
+  def whenNull: Boolean
+
+  override def nullable: Boolean = false
+  override def inputTypes: Seq[DataType] = Seq(BooleanType)
+
+  override def eval(input: InternalRow): Any = {
+val value = child.eval(input)
+Option(value) match {
+  case None => whenNull
+  case other => if (whenNull) {
+value == !boolValue
+  } else {
+value == boolValue
+  }
+}
+  }
+
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+val eval = child.genCode(ctx)
+ev.copy(code = code"""
+  ${eval.code}
+  ${CodeGenerator.javaType(dataType)} ${ev.value} = 
${CodeGenerator.defaultValue(dataType)};
+  if (${eval.isNull}) {
+${ev.value} = $whenNull;
+  } else if ($whenNull) {
+${ev.value} = ${eval.value} == !$boolValue;
+  } else {
+${ev.value} = ${eval.value} == $boolValue;
+  }
+  """, isNull = FalseLiteral)
+  }
+}
+
+case class IsTrue(child: Expression) extends BooleanTest {
+  override def boolValue: Boolean = true
+  override def whenNull: Boolean = false
+  override def sql: String = s"(${child.sql} IS TRUE)"
+}
+
+case class IsNotTrue(child: Expression) extends BooleanTest {
+  override def boolValue: Boolean = true
+  override def whenNull: Boolean = true
+  override def sql: String = s"(${child.sql} IS NOT TRUE)"
+}
+
+case class IsFalse(child: Expression) extends BooleanTest {
+  override def boolValue: Boolean = false
+  override def whenNull: Boolean = false
+  override def sql: String = s"(${child.sql} IS FALSE)"
+}
+
+case class IsNotFalse(child: Expression) extends BooleanTest {
+  override def boolValue: Boolean = false
+  override def whenNull: Boolean = true
+  override def sql: String = s"(${child.sql} IS NOT FALSE)"
+}
+
+object IsUnknown {
+  def apply(child: Expression): Predicate = {
+new IsNull(child) with ExpectsInputTypes {
+  override def inputTypes: Seq[DataType] = Seq(BooleanType)
 
 Review comment:
   +1 for @maropu 's comment.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-28 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308057595
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -110,6 +110,13 @@ package object dsl {
 def isNull: Predicate = IsNull(expr)
 def isNotNull: Predicate = IsNotNull(expr)
 
+def isTrue: Predicate = IsTrue(expr)
+def isNotTrue: Predicate = IsNotTrue(expr)
+def isFalse: Predicate = IsFalse(expr)
+def isNotFalse: Predicate = IsNotFalse(expr)
+def isUnknown: Predicate = IsUnknown(expr)
+def isNotUnknown: Predicate = IsNotUnknown(expr)
 
 Review comment:
   In that case, we should revert this and `test("is true | false | unknown 
expressions")`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-28 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r308057068
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala
 ##
 @@ -110,6 +110,13 @@ package object dsl {
 def isNull: Predicate = IsNull(expr)
 def isNotNull: Predicate = IsNotNull(expr)
 
+def isTrue: Predicate = IsTrue(expr)
+def isNotTrue: Predicate = IsNotTrue(expr)
+def isFalse: Predicate = IsFalse(expr)
+def isNotFalse: Predicate = IsNotFalse(expr)
+def isUnknown: Predicate = IsUnknown(expr)
+def isNotUnknown: Predicate = IsNotUnknown(expr)
 
 Review comment:
   Sorry for adding a comment for the late review rounds, but shall we avoid 
adding DSL since the whole picture is to support PostgreSQL feature parity? How 
do you think about that, @maropu ? Can we remove these DSL addition?


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-20 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r305595789
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1243,6 +1244,12 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
 IsNotNull(e)
   case SqlBaseParser.NULL =>
 IsNull(e)
+  case SqlBaseParser.TRUE =>
+invertIfNotDefined(BooleanTest(e, Some(true)))
+  case SqlBaseParser.FALSE =>
+invertIfNotDefined(BooleanTest(e, Some(false)))
+  case SqlBaseParser.UNKNOWN =>
+invertIfNotDefined(BooleanTest(e, None))
 
 Review comment:
   I'm still reluctant for this as I mentioned before in my previous comments. 
The current PR direction is not aligned to the advice.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-18 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304997464
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1243,6 +1249,24 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
 IsNotNull(e)
   case SqlBaseParser.NULL =>
 IsNull(e)
+  case SqlBaseParser.TRUE if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, Some(true)))
+  case SqlBaseParser.TRUE =>
+checkBooleanTestArgs(e)
+BooleanTest(e, Some(true))
+  case SqlBaseParser.FALSE if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, Some(false)))
+  case SqlBaseParser.FALSE =>
+checkBooleanTestArgs(e)
+BooleanTest(e, Some(false))
+  case SqlBaseParser.UNKNOWN if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, None))
 
 Review comment:
   Ping, @beliefer .


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-18 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304996995
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ##
 @@ -840,3 +840,46 @@ case class GreaterThanOrEqual(left: Expression, right: 
Expression)
 
   protected override def nullSafeEval(input1: Any, input2: Any): Any = 
ordering.gteq(input1, input2)
 }
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
 
 Review comment:
   Thank you for checking. Then, let's remove this `@ExpressionDescription` 
annotation. We don't need this. 


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-18 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304996995
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ##
 @@ -840,3 +840,46 @@ case class GreaterThanOrEqual(left: Expression, right: 
Expression)
 
   protected override def nullSafeEval(input1: Any, input2: Any): Any = 
ordering.gteq(input1, input2)
 }
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
 
 Review comment:
   Yes. Then, let's remove this `@ExpressionDescription` annotation. We don't 
need this. 


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-17 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304542007
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ##
 @@ -840,3 +840,46 @@ case class GreaterThanOrEqual(left: Expression, right: 
Expression)
 
   protected override def nullSafeEval(input1: Any, input2: Any): Any = 
ordering.gteq(input1, input2)
 }
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
 
 Review comment:
   Does PostgreSQL has a function like this, @beliefer ?
   This guess your example will not work since we didn't register this as a 
function yet.
   Until now, this PR only support `IS TRUE|FALSE|UNKNOWN` SQL syntax.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-17 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304538853
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1243,6 +1249,24 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
 IsNotNull(e)
   case SqlBaseParser.NULL =>
 IsNull(e)
+  case SqlBaseParser.TRUE if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, Some(true)))
+  case SqlBaseParser.TRUE =>
+checkBooleanTestArgs(e)
+BooleanTest(e, Some(true))
+  case SqlBaseParser.FALSE if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, Some(false)))
+  case SqlBaseParser.FALSE =>
+checkBooleanTestArgs(e)
+BooleanTest(e, Some(false))
+  case SqlBaseParser.UNKNOWN if ctx.NOT != null =>
+checkBooleanTestArgs(e)
+Not(BooleanTest(e, None))
 
 Review comment:
   Ur, IIRC, @maropu 's suggestion is the following. @maropu . Could you check 
this again?
   ```scala
  case SqlBaseParser.UNKNOWN if ctx.NOT != null =>
checkBooleanTestArgs(e)
   -Not(BooleanTest(e, None))
   +IsNotNull(e)
  case SqlBaseParser.UNKNOWN =>
checkBooleanTestArgs(e)
   -BooleanTest(e, None)
   +IsNull(e)
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-17 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304536038
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/booleanExpressions.scala
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, 
ExprCode}
+import org.apache.spark.sql.types.BooleanType
+
+/**
+ * String to indicate which boolean test selected.
+ */
+object BooleanTest {
+  val TRUE = "TRUE"
+  val FALSE = "FALSE"
+  val UNKNOWN = "UNKNOWN"
+
+  def calculate(input: Any, booleanValue: String): Boolean = {
+booleanValue match {
+  case TRUE => input == true
+  case FALSE => input == false
+  case UNKNOWN => input == null
+  case _ => throw new AnalysisException("Boolean test value must be one of 
TRUE, " +
+"FALSE and UNKNOWN.")
+}
+  }
+}
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
+   true
+  """)
+case class BooleanTest(child: Expression, booleanValue: String)
+  extends UnaryExpression with Predicate {
+
+  override def nullable: Boolean = false
+
+  override def eval(input: InternalRow): Any = {
+BooleanTest.calculate(child.eval(input), booleanValue)
+  }
+
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+defineCodeGen(ctx, ev, input =>
+  s"""
+
org.apache.spark.sql.catalyst.expressions.BooleanTest.calculate($input, 
"$booleanValue")
+  """
+)
+  }
+
+  override def sql: String = s"(${child.sql} IS $booleanValue)"
+}
+
 
 Review comment:
   nit. Empty 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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-17 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304532212
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1223,6 +1223,12 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case c: CreateNamedStruct => c.valExprs
   case other => Seq(other)
 }
+// Check the argument of boolean test is valid.
+def checkBooleanTestArgs(e: Expression): Unit = e.dataType match {
 
 Review comment:
   Oh. My bad. This is already inside a 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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-17 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304530500
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/BooleanExpressionsSuite.scala
 ##
 @@ -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.spark.sql.catalyst.expressions
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.expressions.BooleanTest._
+import org.apache.spark.sql.types._
+
+class BooleanExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
+
+  val row0 = create_row(null)
+  val row1 = create_row(false)
+  val row2 = create_row(true)
+
+  test("istrue and isnottrue") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), TRUE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), TRUE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), TRUE), 
false, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
TRUE)), true, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), TRUE), 
true, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), TRUE)), 
false, row2)
+  }
+
+  test("isfalse and isnotfalse") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), FALSE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), FALSE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), FALSE), 
true, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
FALSE)), false, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), FALSE), 
false, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), 
FALSE)), true, row2)
+  }
+
+  test("isunknown and isnotunknown") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), UNKNOWN), 
true, row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), UNKNOWN)), 
false, row0)
+  }
+
+}
+
 
 Review comment:
   Nope. If you hit error, it's due to your editor behavior.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304200836
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##
 @@ -1223,6 +1223,12 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   case c: CreateNamedStruct => c.valExprs
   case other => Seq(other)
 }
+// Check the argument of boolean test is valid.
+def checkBooleanTestArgs(e: Expression): Unit = e.dataType match {
 
 Review comment:
   Since this is used only here, `private def`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304200461
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/booleanExpressions.scala
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, 
ExprCode}
+import org.apache.spark.sql.types.BooleanType
+
+/**
+ * String to indicate which boolean test selected.
+ */
+object BooleanTest {
+  val TRUE = "TRUE"
+  val FALSE = "FALSE"
+  val UNKNOWN = "UNKNOWN"
+
+  def calculate(input: Any, booleanValue: String): Boolean = {
+booleanValue match {
+  case TRUE => input == true
+  case FALSE => input == false
+  case UNKNOWN => input == null
+  case _ => throw new AnalysisException("Boolean test value must be one of 
TRUE, " +
+"FALSE and UNKNOWN.")
+}
+  }
+}
 
 Review comment:
   Shall we avoid to use `booleanValue: String`? Also, we don't need to have 
enum-like strings `val TRUE = "TRUE"` and so on. The following will be better 
in `Scala` world.
   ```scala
   object BooleanTest {
 def calculate(input: Any, booleanValue: Option[Boolean]): Boolean = {
   booleanValue match {
 case Some(true) => input == true
 case Some(false) => input == false
 case None => input == null
 case _ => throw new AnalysisException("Boolean test value must be one 
of TRUE, " +
   "FALSE and UNKNOWN.")
   }
 }
   }
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304199384
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/booleanExpressions.scala
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, 
ExprCode}
+import org.apache.spark.sql.types.BooleanType
+
 
 Review comment:
   +1 for @maropu 's comment. Let's move this to `predicates.scala`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304198739
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/booleanExpressions.scala
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, 
ExprCode}
+import org.apache.spark.sql.types.BooleanType
+
+/**
+ * String to indicate which boolean test selected.
+ */
+object BooleanTest {
+  val TRUE = "TRUE"
+  val FALSE = "FALSE"
+  val UNKNOWN = "UNKNOWN"
+
+  def calculate(input: Any, booleanValue: String): Boolean = {
+booleanValue match {
+  case TRUE => input == true
+  case FALSE => input == false
+  case UNKNOWN => input == null
+  case _ => throw new AnalysisException("Boolean test value must be one of 
TRUE, " +
+"FALSE and UNKNOWN.")
+}
+  }
+}
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
+   true
+  """)
 
 Review comment:
   Please add `since`, too.
   ```
   since = "3.0.0")
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304198487
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/BooleanExpressionsSuite.scala
 ##
 @@ -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.spark.sql.catalyst.expressions
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.expressions.BooleanTest._
+import org.apache.spark.sql.types._
+
+class BooleanExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
+
+  val row0 = create_row(null)
+  val row1 = create_row(false)
+  val row2 = create_row(true)
+
+  test("istrue and isnottrue") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), TRUE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), TRUE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), TRUE), 
false, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
TRUE)), true, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), TRUE), 
true, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), TRUE)), 
false, row2)
+  }
+
+  test("isfalse and isnotfalse") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), FALSE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), FALSE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), FALSE), 
true, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
FALSE)), false, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), FALSE), 
false, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), 
FALSE)), true, row2)
+  }
+
+  test("isunknown and isnotunknown") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), UNKNOWN), 
true, row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), UNKNOWN)), 
false, row0)
 
 Review comment:
   Can we have negative cases for the above three tests? For example, here, we 
need to catch the exception when the input value is not `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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304198024
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/BooleanExpressionsSuite.scala
 ##
 @@ -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.spark.sql.catalyst.expressions
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.expressions.BooleanTest._
+import org.apache.spark.sql.types._
+
+class BooleanExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
 
 Review comment:
   Maybe, `BooleanTestSuite` is better since it's referring `BooleanTest` 
specifically.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304197674
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/BooleanExpressionsSuite.scala
 ##
 @@ -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.spark.sql.catalyst.expressions
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.expressions.BooleanTest._
+import org.apache.spark.sql.types._
+
+class BooleanExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
+
+  val row0 = create_row(null)
+  val row1 = create_row(false)
+  val row2 = create_row(true)
+
+  test("istrue and isnottrue") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), TRUE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), TRUE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), TRUE), 
false, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
TRUE)), true, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), TRUE), 
true, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), TRUE)), 
false, row2)
+  }
+
+  test("isfalse and isnotfalse") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), FALSE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), FALSE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), FALSE), 
true, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
FALSE)), false, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), FALSE), 
false, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), 
FALSE)), true, row2)
+  }
+
+  test("isunknown and isnotunknown") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), UNKNOWN), 
true, row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), UNKNOWN)), 
false, row0)
+  }
+
+}
+
 
 Review comment:
   ditto.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304197644
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/BooleanExpressionsSuite.scala
 ##
 @@ -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.spark.sql.catalyst.expressions
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.expressions.BooleanTest._
+import org.apache.spark.sql.types._
+
+class BooleanExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
+
+  val row0 = create_row(null)
+  val row1 = create_row(false)
+  val row2 = create_row(true)
+
+  test("istrue and isnottrue") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), TRUE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), TRUE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), TRUE), 
false, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
TRUE)), true, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), TRUE), 
true, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), TRUE)), 
false, row2)
+  }
+
+  test("isfalse and isnotfalse") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), FALSE), false, 
row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), FALSE)), 
true, row0)
+checkEvaluation(BooleanTest(Literal.create(false, BooleanType), FALSE), 
true, row1)
+checkEvaluation(Not(BooleanTest(Literal.create(false, BooleanType), 
FALSE)), false, row1)
+checkEvaluation(BooleanTest(Literal.create(true, BooleanType), FALSE), 
false, row2)
+checkEvaluation(Not(BooleanTest(Literal.create(true, BooleanType), 
FALSE)), true, row2)
+  }
+
+  test("isunknown and isnotunknown") {
+checkEvaluation(BooleanTest(Literal.create(null, NullType), UNKNOWN), 
true, row0)
+checkEvaluation(Not(BooleanTest(Literal.create(null, NullType), UNKNOWN)), 
false, row0)
+  }
+
 
 Review comment:
   nit. empty 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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] Support ANSI SQL Boolean-Predicate syntax

2019-07-16 Thread GitBox
dongjoon-hyun commented on a change in pull request #25074: [SPARK-27924][SQL] 
Support ANSI SQL Boolean-Predicate syntax 
URL: https://github.com/apache/spark/pull/25074#discussion_r304197306
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/booleanExpressions.scala
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, 
ExprCode}
+import org.apache.spark.sql.types.BooleanType
+
+/**
+ * String to indicate which boolean test selected.
+ */
+object BooleanTest {
+  val TRUE = "TRUE"
+  val FALSE = "FALSE"
+  val UNKNOWN = "UNKNOWN"
+
+  def calculate(input: Any, booleanValue: String): Boolean = {
+booleanValue match {
+  case TRUE => input == true
+  case FALSE => input == false
+  case UNKNOWN => input == null
+  case _ => throw new AnalysisException("Boolean test value must be one of 
TRUE, " +
+"FALSE and UNKNOWN.")
+}
+  }
+}
+
+/**
+ * Test the value of an expression is true, false, or unknown.
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr, booleanValue) - Returns true if `expr` equals 
booleanValue, " +
+"or false otherwise.",
+  arguments = """
+Arguments:
+  * expr - a boolean expression
+  * booleanValue - a boolean value represented by a string. booleanValue 
must be one
+  of TRUE, FALSE and UNKNOWN.
+  """,
+  examples = """
+Examples:
+> SELECT _FUNC_(1 > 2, true);
+   false
+> SELECT _FUNC_(2 > 1, true);
+   true
+  """)
+case class BooleanTest(child: Expression, booleanValue: String)
 
 Review comment:
   +1 for @maropu 's direction. Let's reuse the existing one.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org