You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/04/28 21:56:45 UTC

[GitHub] [iceberg] RussellSpitzer opened a new pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

RussellSpitzer opened a new pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543


   Before this patch if Spark passes through a filter on an Instant the
   comparison will fail in Iceberg due to our lack of handling of Instant
   literals. To fix this we convert Instants and LocalDates like we do for Timestamp and
   Date in the filter conversion code.


-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] stevenzwu commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r624610296



##########
File path: spark3/src/test/java/org/apache/iceberg/spark/TestSparkFilters.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.iceberg.spark;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.spark.sql.sources.GreaterThan;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSparkFilters {

Review comment:
       thanks for adding the test.
   
   I tried these literals with Spark 3.0 and they works fine. Are they parsed into some other type than `Instant`? A simple unit test seems to suggest they aren't parseable by `Instant`
   
   2021-04-29T17:00:00
   2021-04-29T17:00:00+00:00




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r623501203



##########
File path: spark3/src/main/java/org/apache/iceberg/spark/SparkFilters.java
##########
@@ -198,6 +200,10 @@ private static Object convertLiteral(Object value) {
       return DateTimeUtils.fromJavaTimestamp((Timestamp) value);
     } else if (value instanceof Date) {
       return DateTimeUtils.fromJavaDate((Date) value);
+    } else if (value instanceof Instant) {

Review comment:
       https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L81 - Spark's literal Instant is always a timestamp
   
   https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L83 - Local date Is always a LocalDate
   
   If there is a type mismatch Spark will be doing the conversions and we won't end up with a Instant or LocalDate, we'll get whatever Spark thinks is the correct corresponding type for the Table column
   
   




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] yyanyy commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
yyanyy commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r623493930



##########
File path: spark3/src/main/java/org/apache/iceberg/spark/SparkFilters.java
##########
@@ -198,6 +200,10 @@ private static Object convertLiteral(Object value) {
       return DateTimeUtils.fromJavaTimestamp((Timestamp) value);
     } else if (value instanceof Date) {
       return DateTimeUtils.fromJavaDate((Date) value);
+    } else if (value instanceof Instant) {

Review comment:
       Do we know passed in `Instant` always correspond to type `timestamptz` but not `date`?




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r623501203



##########
File path: spark3/src/main/java/org/apache/iceberg/spark/SparkFilters.java
##########
@@ -198,6 +200,10 @@ private static Object convertLiteral(Object value) {
       return DateTimeUtils.fromJavaTimestamp((Timestamp) value);
     } else if (value instanceof Date) {
       return DateTimeUtils.fromJavaDate((Date) value);
+    } else if (value instanceof Instant) {

Review comment:
       
   https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L81
   
   > LGTM, though I'm not a spark expert; some minor questions. Do we know if this only impact spark3 but not 2?
   
   Yep the patch to add support for these literals only exists in Spark3
   https://issues.apache.org/jira/browse/SPARK-26902




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#issuecomment-829706460


   > LGTM, though I'm not a spark expert; some minor questions. Do we know if this only impact spark3 but not 2?
   
   Yep the patch to add support for these literals only exists in Spark3
   https://issues.apache.org/jira/browse/SPARK-26902


-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue merged pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
rdblue merged pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543


   


-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#issuecomment-828807127


   Fixes #2530


-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r623501203



##########
File path: spark3/src/main/java/org/apache/iceberg/spark/SparkFilters.java
##########
@@ -198,6 +200,10 @@ private static Object convertLiteral(Object value) {
       return DateTimeUtils.fromJavaTimestamp((Timestamp) value);
     } else if (value instanceof Date) {
       return DateTimeUtils.fromJavaDate((Date) value);
+    } else if (value instanceof Instant) {

Review comment:
       https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L81 - Spark's literal Instant is always a timestamp
   
   https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L83 - Is always a LocalDate
   
   If there is a type mismatch Spark will be doing the conversions and we won't end up with a Instant or LocalDate, we'll get whatever Spark thinks is the correct corresponding type for the Table column
   
   > LGTM, though I'm not a spark expert; some minor questions. Do we know if this only impact spark3 but not 2?
   
   Yep the patch to add support for these literals only exists in Spark3
   https://issues.apache.org/jira/browse/SPARK-26902

##########
File path: spark3/src/main/java/org/apache/iceberg/spark/SparkFilters.java
##########
@@ -198,6 +200,10 @@ private static Object convertLiteral(Object value) {
       return DateTimeUtils.fromJavaTimestamp((Timestamp) value);
     } else if (value instanceof Date) {
       return DateTimeUtils.fromJavaDate((Date) value);
+    } else if (value instanceof Instant) {

Review comment:
       https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L81 - Spark's literal Instant is always a timestamp
   
   https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L83 - Is always a LocalDate
   
   If there is a type mismatch Spark will be doing the conversions and we won't end up with a Instant or LocalDate, we'll get whatever Spark thinks is the correct corresponding type for the Table column
   
   




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] RussellSpitzer commented on a change in pull request #2543: Spark: Handle Instant and LocalDate in filter expressions (#2530)

Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on a change in pull request #2543:
URL: https://github.com/apache/iceberg/pull/2543#discussion_r624617463



##########
File path: spark3/src/test/java/org/apache/iceberg/spark/TestSparkFilters.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.iceberg.spark;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.spark.sql.sources.GreaterThan;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSparkFilters {

Review comment:
       As I noted in the Issue #2530 , for some reason Spark is only parsing these types as instant in 3.1.1 Spark-Sql Shell. But you can always programmatically pass them through as well.
   
   > The user reported the exception I noted at the top of this issue, I attempt to reproduce and cannot. I then find the following matrix of behaviors.
   > 
   > Spark 3.0.2 - spark-shell - No Issue
   > Spark 3.0.2 - spark-sql - No issue
   > Spark 3.1.1 - spark-shell - No issue
   > Spark 3.1.1 - spark-sql - Exception - Query Fails - not Literal From Instant
   
   I didn't try to find out why Spark 3.1.1 was parsing these (but only in spark-sql shell) as instants, I figured we might as well just support it since it now is a possibility in 3.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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org