You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2019/10/17 20:39:16 UTC

[calcite-avatica] branch master updated (da71884 -> 73fac75)

This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git.


    from da71884  [CALCITE-3384] Support Kerberos-authentication using SPNEGO over HTTPS
     new be246b9  [CALCITE-3199] DateTimeUtils.unixDateCeil should not return the same value as unixDateFloor (Zhenghua Gao)
     new 72bbbfc  [CALCITE-3412] FLOOR(timestamp TO WEEK) gives wrong result
     new 73fac75  Cosmetic

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 appveyor.yml                                       |  6 +--
 .../java/org/apache/calcite/avatica/SqlType.java   |  2 -
 .../remote/AvaticaCommonsHttpClientSpnegoImpl.java |  4 +-
 .../org/apache/calcite/avatica/remote/Service.java |  4 +-
 .../apache/calcite/avatica/util/DateTimeUtils.java | 26 +++++++++-
 .../avatica/remote/ProtobufSerializationTest.java  | 56 ++++++++++++----------
 .../calcite/avatica/util/DateTimeUtilsTest.java    | 44 +++++++++++++++++
 .../calcite/avatica/util/StructImplTest.java       | 17 ++++---
 docker/src/main/dockerhub/hooks/build              |  2 +-
 docker/src/main/dockerhub/hooks/post_push          |  2 +-
 .../apache/calcite/avatica/jdbc/JdbcMetaTest.java  |  4 +-
 site/_docs/history.md                              |  2 +-
 site/_docs/howto.md                                |  2 +-
 site/_docs/index.md                                |  2 +-
 site/_posts/2019-05-13-release-1.15.0.md           |  2 +-
 site/downloads/avatica-go.md                       |  2 +-
 site/downloads/avatica.md                          |  2 +-
 17 files changed, 125 insertions(+), 54 deletions(-)


[calcite-avatica] 03/03: Cosmetic

Posted by jh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git

commit 73fac75befaaf3caa3871656d0d0b7adbd91f7cf
Author: Julian Hyde <jh...@apache.org>
AuthorDate: Thu Oct 17 01:42:02 2019 -0700

    Cosmetic
    
    Remove trailing whitespace, end files with a newline, add paragraph
    tags to javadoc, and move '.' operators to the beginning of lines.
---
 appveyor.yml                                       |  6 +--
 .../java/org/apache/calcite/avatica/SqlType.java   |  2 -
 .../remote/AvaticaCommonsHttpClientSpnegoImpl.java |  4 +-
 .../org/apache/calcite/avatica/remote/Service.java |  4 +-
 .../avatica/remote/ProtobufSerializationTest.java  | 56 ++++++++++++----------
 .../calcite/avatica/util/StructImplTest.java       | 17 ++++---
 docker/src/main/dockerhub/hooks/build              |  2 +-
 docker/src/main/dockerhub/hooks/post_push          |  2 +-
 .../apache/calcite/avatica/jdbc/JdbcMetaTest.java  |  4 +-
 site/_docs/history.md                              |  2 +-
 site/_docs/howto.md                                |  2 +-
 site/_docs/index.md                                |  2 +-
 site/_posts/2019-05-13-release-1.15.0.md           |  2 +-
 site/downloads/avatica-go.md                       |  2 +-
 site/downloads/avatica.md                          |  2 +-
 15 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index eb44d05..846694d 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -28,12 +28,12 @@ branches:
     - /^branch-.*$/
     - /^[0-9]+-.*$/
 matrix:
-  fast_finish: true  
+  fast_finish: true
 environment:
-  matrix:  
+  matrix:
     - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
     - JAVA_HOME: C:\Program Files\Java\jdk9
-    - JAVA_HOME: C:\Program Files\Java\jdk10        
+    - JAVA_HOME: C:\Program Files\Java\jdk10
     - JAVA_HOME: C:\Program Files\Java\jdk11
 build_script:
   - mvn clean -V install -DskipTests -Dmaven.javadoc.skip=true -Djavax.net.ssl.trustStorePassword=changeit
diff --git a/core/src/main/java/org/apache/calcite/avatica/SqlType.java b/core/src/main/java/org/apache/calcite/avatica/SqlType.java
index 5111f9f..840e218 100644
--- a/core/src/main/java/org/apache/calcite/avatica/SqlType.java
+++ b/core/src/main/java/org/apache/calcite/avatica/SqlType.java
@@ -195,7 +195,6 @@ import java.util.Map;
  *
  * <p><a id="B5">TABLE B-5</a>: Conversions performed by {@code setObject} and
  * {@code setNull} between Java object types and target JDBC types
- *
  * <!--
  * CHECKSTYLE: OFF
  * -->
@@ -244,7 +243,6 @@ import java.util.Map;
  *
  * <p><a id="B6">TABLE B-6</a>: Use of {@code ResultSet} getter methods to
  * retrieve JDBC data types
- *
  * <!--
  * CHECKSTYLE: OFF
  * -->
diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientSpnegoImpl.java b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientSpnegoImpl.java
index 635c711..d08d36a 100644
--- a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientSpnegoImpl.java
+++ b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientSpnegoImpl.java
@@ -40,10 +40,12 @@ import org.slf4j.LoggerFactory;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.security.Principal;
+
 /**
  * Implementation of an AvaticaHttpClient which uses SPNEGO.
  *
- * ( at this point it could probably be just merged back into AvaticaCommonsHttpClientImpl)
+ * <p>(At this point it could probably be just merged back into
+ * {@link AvaticaCommonsHttpClientImpl}.)
  */
 public class AvaticaCommonsHttpClientSpnegoImpl extends AvaticaCommonsHttpClientImpl {
   private static final Logger LOG = LoggerFactory
diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/Service.java b/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
index 76e1e6b..1a5aa43 100644
--- a/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
+++ b/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
@@ -238,8 +238,8 @@ public interface Service {
    * {@link org.apache.calcite.avatica.Meta#getDatabaseProperties(Meta.ConnectionHandle)}. */
   class DatabasePropertyRequest extends Request {
     private static final FieldDescriptor CONNECTION_ID_DESCRIPTOR =
-        Requests.DatabasePropertyRequest.getDescriptor().
-        findFieldByNumber(Requests.DatabasePropertyRequest.CONNECTION_ID_FIELD_NUMBER);
+        Requests.DatabasePropertyRequest.getDescriptor()
+            .findFieldByNumber(Requests.DatabasePropertyRequest.CONNECTION_ID_FIELD_NUMBER);
 
     public final String connectionId;
 
diff --git a/core/src/test/java/org/apache/calcite/avatica/remote/ProtobufSerializationTest.java b/core/src/test/java/org/apache/calcite/avatica/remote/ProtobufSerializationTest.java
index 39787dd..0efcb02 100644
--- a/core/src/test/java/org/apache/calcite/avatica/remote/ProtobufSerializationTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/remote/ProtobufSerializationTest.java
@@ -96,22 +96,24 @@ public class ProtobufSerializationTest {
     final long maxRowCount = 200L;
 
     // The "current" serialization strategy.
-    Requests.PrepareRequest protoPrepare = Requests.PrepareRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowsTotal(maxRowCount).build();
+    Requests.PrepareRequest protoPrepare = Requests.PrepareRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowsTotal(maxRowCount)
+        .build();
 
     Service.PrepareRequest prepareReq = new Service.PrepareRequest().deserialize(protoPrepare);
     assertEquals(maxRowCount, prepareReq.maxRowCount);
 
     // The "old" serialization strategy.
-    protoPrepare = Requests.PrepareRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowCount(maxRowCount).build();
+    protoPrepare = Requests.PrepareRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowCount(maxRowCount)
+        .build();
 
     prepareReq = new Service.PrepareRequest().deserialize(protoPrepare);
     assertEquals(maxRowCount, prepareReq.maxRowCount);
 
     // Both the new and old provided should default to the new
-    protoPrepare = Requests.PrepareRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
+    protoPrepare = Requests.PrepareRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
         .setMaxRowsTotal(maxRowCount).build();
 
     prepareReq = new Service.PrepareRequest().deserialize(protoPrepare);
@@ -162,18 +164,19 @@ public class ProtobufSerializationTest {
     final int maxRowsInFirstFrame = 50;
 
     // The "current" serialization strategy (maxRowsTotal and firstFrameMaxSize)
-    Requests.PrepareAndExecuteRequest protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowsTotal(maxRowCount).
-        setFirstFrameMaxSize(maxRowsInFirstFrame).build();
+    Requests.PrepareAndExecuteRequest protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowsTotal(maxRowCount)
+        .setFirstFrameMaxSize(maxRowsInFirstFrame).build();
 
-    Service.PrepareAndExecuteRequest prepareAndExecuteReq = new Service.PrepareAndExecuteRequest().
-        deserialize(protoPrepare);
+    Service.PrepareAndExecuteRequest prepareAndExecuteReq = new Service.PrepareAndExecuteRequest()
+        .deserialize(protoPrepare);
     assertEquals(maxRowCount, prepareAndExecuteReq.maxRowCount);
     assertEquals(maxRowsInFirstFrame, prepareAndExecuteReq.maxRowsInFirstFrame);
 
     // The "old" serialization strategy (maxRowCount)
-    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowCount(maxRowCount).build();
+    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowCount(maxRowCount)
+        .build();
 
     prepareAndExecuteReq = new Service.PrepareAndExecuteRequest().deserialize(protoPrepare);
     assertEquals(maxRowCount, prepareAndExecuteReq.maxRowCount);
@@ -182,8 +185,8 @@ public class ProtobufSerializationTest {
 
     // Both the new and old provided should default to the new (firstFrameMaxSize should be the
     // the same as what ultimately is set to maxRowCount)
-    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
+    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
         .setMaxRowsTotal(maxRowCount).build();
 
     prepareAndExecuteReq = new Service.PrepareAndExecuteRequest().deserialize(protoPrepare);
@@ -192,8 +195,8 @@ public class ProtobufSerializationTest {
         prepareAndExecuteReq.maxRowsInFirstFrame);
 
     // Same as previous example, but explicitly setting maxRowsInFirstFrame too
-    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder().
-        setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
+    protoPrepare = Requests.PrepareAndExecuteRequest.newBuilder()
+        .setConnectionId(connectionId).setSql(sql).setMaxRowCount(500L)
         .setMaxRowsTotal(maxRowCount).setFirstFrameMaxSize(maxRowsInFirstFrame).build();
 
     prepareAndExecuteReq = new Service.PrepareAndExecuteRequest().deserialize(protoPrepare);
@@ -225,25 +228,26 @@ public class ProtobufSerializationTest {
     final int maxSize = 200;
 
     // The "current" serialization strategy.
-    Requests.FetchRequest protoFetch = Requests.FetchRequest.newBuilder().
-        setConnectionId(connectionId).setStatementId(statementId).
-        setOffset(offset).setFrameMaxSize(maxSize).build();
+    Requests.FetchRequest protoFetch = Requests.FetchRequest.newBuilder()
+        .setConnectionId(connectionId).setStatementId(statementId)
+        .setOffset(offset).setFrameMaxSize(maxSize).build();
 
     Service.FetchRequest fetchReq = new Service.FetchRequest().deserialize(protoFetch);
     assertEquals(maxSize, fetchReq.fetchMaxRowCount);
 
     // The "old" serialization strategy.
-    protoFetch = Requests.FetchRequest.newBuilder().
-        setConnectionId(connectionId).setStatementId(statementId).
-        setOffset(offset).setFetchMaxRowCount(maxSize).build();
+    protoFetch = Requests.FetchRequest.newBuilder()
+        .setConnectionId(connectionId).setStatementId(statementId)
+        .setOffset(offset).setFetchMaxRowCount(maxSize).build();
 
     fetchReq = new Service.FetchRequest().deserialize(protoFetch);
     assertEquals(maxSize, fetchReq.fetchMaxRowCount);
 
     // Both the new and old provided should default to the new
-    protoFetch = Requests.FetchRequest.newBuilder().
-        setConnectionId(connectionId).setStatementId(statementId).
-        setOffset(offset).setFetchMaxRowCount(100).setFrameMaxSize(maxSize).build();
+    protoFetch = Requests.FetchRequest.newBuilder()
+        .setConnectionId(connectionId).setStatementId(statementId)
+        .setOffset(offset).setFetchMaxRowCount(100).setFrameMaxSize(maxSize)
+        .build();
 
     fetchReq = new Service.FetchRequest().deserialize(protoFetch);
     assertEquals(maxSize, fetchReq.fetchMaxRowCount);
diff --git a/core/src/test/java/org/apache/calcite/avatica/util/StructImplTest.java b/core/src/test/java/org/apache/calcite/avatica/util/StructImplTest.java
index 1058125..9e9fd6e 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/StructImplTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/StructImplTest.java
@@ -47,17 +47,20 @@ public class StructImplTest {
    */
   private static class ColumnInputBundle<T> {
     private final ColumnMetaData metaData;
+
     /**
      * The input values for the given column.
      *
-     * These values are used to construct the rows of a ResultSet.
+     * <p>These values are used to construct the rows of a ResultSet.
      */
     private final List<Object> inputValues;
+
     /**
      * The expected values for the given column.
      *
-     * These values are used to verify that the result obtained from a ResultSet is correct. Note,
-     * that inputValues and expectedValues are not necessarily equal.
+     * <p>These values are used to verify that the result obtained from a
+     * ResultSet is correct. Note that inputValues and expectedValues are not
+     * necessarily equal.
      */
     private final List<T> expectedValues;
 
@@ -88,9 +91,7 @@ public class StructImplTest {
         0,
         ColumnMetaData.struct(
             Arrays.asList(
-                MetaImpl.columnMetaData("INT", 0, int.class, false)
-            )
-        ),
+                MetaImpl.columnMetaData("INT", 0, int.class, false))),
         false);
 
     ColumnMetaData twoAttrStructMeta = MetaImpl.columnMetaData(
@@ -99,9 +100,7 @@ public class StructImplTest {
         ColumnMetaData.struct(
             Arrays.asList(
                 MetaImpl.columnMetaData("INT", 0, int.class, false),
-                MetaImpl.columnMetaData("INT", 1, int.class, false)
-            )
-        ),
+                MetaImpl.columnMetaData("INT", 1, int.class, false))),
         false);
 
     List<Struct> oneAttrStructData = new ArrayList<>(numRows);
diff --git a/docker/src/main/dockerhub/hooks/build b/docker/src/main/dockerhub/hooks/build
index cfc048d..e193f3c 100644
--- a/docker/src/main/dockerhub/hooks/build
+++ b/docker/src/main/dockerhub/hooks/build
@@ -15,4 +15,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-docker build --build-arg AVATICA_VERSION="$DOCKER_TAG" -t $IMAGE_NAME .
\ No newline at end of file
+docker build --build-arg AVATICA_VERSION="$DOCKER_TAG" -t $IMAGE_NAME .
diff --git a/docker/src/main/dockerhub/hooks/post_push b/docker/src/main/dockerhub/hooks/post_push
index c864128..affc991 100644
--- a/docker/src/main/dockerhub/hooks/post_push
+++ b/docker/src/main/dockerhub/hooks/post_push
@@ -18,4 +18,4 @@
 HSQLDB_IMAGE_NAME=apache/calcite-avatica-hypersql:$DOCKER_TAG
 
 docker build --build-arg AVATICA_VERSION="$DOCKER_TAG" -f Dockerfile.hypersql -t $HSQLDB_IMAGE_NAME .
-docker push $HSQLDB_IMAGE_NAME
\ No newline at end of file
+docker push $HSQLDB_IMAGE_NAME
diff --git a/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java b/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
index f3ebc8a..494b9ab 100644
--- a/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
+++ b/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
@@ -112,8 +112,8 @@ public class JdbcMetaTest {
     Mockito.when(statementCache.getIfPresent(statementId)).thenReturn(statementInfo);
     Mockito.when(statement.getResultSet()).thenReturn(null);
     // The real methods
-    Mockito.when(meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null)).
-        thenCallRealMethod();
+    Mockito.when(meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null))
+        .thenCallRealMethod();
     Mockito.doCallRealMethod().when(meta).setMaxRows(statement, maxRows);
 
     // Call our method
diff --git a/site/_docs/history.md b/site/_docs/history.md
index ee6eabb..19e1150 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -97,7 +97,7 @@ Tests
   Update appveyor.yml to enable Appveyor testing against JDK 11
 * [<a href="https://issues.apache.org/jira/browse/CALCITE-2961">CALCITE-2961</a>]
   Enable Travis to test against JDK 13
-  
+
 Website and Documentation
 
 * Update to new git URL (switch to gitbox)
diff --git a/site/_docs/howto.md b/site/_docs/howto.md
index a3344e1..b9c0141 100644
--- a/site/_docs/howto.md
+++ b/site/_docs/howto.md
@@ -524,7 +524,7 @@ Tip: Push the git tag only after the staged nexus artifacts are promoted in the
 tag triggers Docker Hub to start building the docker images immediately and the build will pull in the promoted artifacts.
 If the artifacts are not yet available, the build on Docker Hub will fail. It's best to continue with the following steps
 after you have confirmed that the nexus artifacts were promoted properly.
- 
+
 ### Publishing directly in your environment:
 Copy the Git tag:
 
diff --git a/site/_docs/index.md b/site/_docs/index.md
index c478feb..249fcf7 100644
--- a/site/_docs/index.md
+++ b/site/_docs/index.md
@@ -180,4 +180,4 @@ highly welcomed!
 * Language: JavaScript
 * *License*: [MIT](https://opensource.org/licenses/MIT)
 * Any Avatica version
-* *Maintainer*: Waylay.io
\ No newline at end of file
+* *Maintainer*: Waylay.io
diff --git a/site/_posts/2019-05-13-release-1.15.0.md b/site/_posts/2019-05-13-release-1.15.0.md
index ea9efe8..9d944bf 100644
--- a/site/_posts/2019-05-13-release-1.15.0.md
+++ b/site/_posts/2019-05-13-release-1.15.0.md
@@ -34,4 +34,4 @@ See the list of [bug fixes and new features]({{ site.baseurl }}/docs/history.htm
 for more information.
 
 Consumers of Avatica are encouraged to skip the 1.14.0 release and upgrade directly to
-1.15.0 due to the aforementioned regression.
\ No newline at end of file
+1.15.0 due to the aforementioned regression.
diff --git a/site/downloads/avatica-go.md b/site/downloads/avatica-go.md
index 684d238..1371273 100644
--- a/site/downloads/avatica-go.md
+++ b/site/downloads/avatica-go.md
@@ -120,4 +120,4 @@ or
 {% highlight shell %}
 % pgp -ka KEYS
 % pgp downloaded_file.asc
-{% endhighlight %}
\ No newline at end of file
+{% endhighlight %}
diff --git a/site/downloads/avatica.md b/site/downloads/avatica.md
index 69f9c63..df5b85f 100644
--- a/site/downloads/avatica.md
+++ b/site/downloads/avatica.md
@@ -154,4 +154,4 @@ As of Apache Calcite Avatica 1.9.0, the following un-shaded client artifact is a
 ## Docker images
 
 From release 1.10.0 onwards, Docker images for Avatica Server are available at
-[Docker Hub](https://hub.docker.com/r/apache/calcite-avatica).
\ No newline at end of file
+[Docker Hub](https://hub.docker.com/r/apache/calcite-avatica).


[calcite-avatica] 02/03: [CALCITE-3412] FLOOR(timestamp TO WEEK) gives wrong result

Posted by jh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git

commit 72bbbfc964e7805e1b09bfdb47f5472d37050c39
Author: Julian Hyde <jh...@apache.org>
AuthorDate: Thu Oct 17 01:37:40 2019 -0700

    [CALCITE-3412] FLOOR(timestamp TO WEEK) gives wrong result
    
    Fix DateTimeUtils.julianDateFloor so that unixDateFloor etc. give the
    right result.
---
 .../apache/calcite/avatica/util/DateTimeUtils.java | 24 ++++++++++++++++++
 .../calcite/avatica/util/DateTimeUtilsTest.java    | 29 ++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
index 5efa210..6969f77 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
@@ -926,11 +926,35 @@ public class DateTimeUtils {
         ++year;
       }
       return ymdToUnixDate(year, 1, 1);
+    case QUARTER:
+      final int q = (month - 1) / 3;
+      if (!floor) {
+        if (month - 1 > q * 3 || day > 1) {
+          if (q == 3) {
+            ++year;
+            month = 1;
+          } else {
+            month = q * 3 + 4;
+          }
+        }
+      } else {
+        month = q * 3 + 1;
+      }
+      return ymdToUnixDate(year, month, 1);
     case MONTH:
       if (!floor && day > 1) {
         ++month;
       }
       return ymdToUnixDate(year, month, 1);
+    case WEEK:
+      final int dow = (int) floorMod(julian + 1, 7); // sun=0, sat=6
+      int offset = dow;
+      if (!floor && offset > 0) {
+        offset -= 7;
+      }
+      return ymdToUnixDate(year, month, day) - offset;
+    case DAY:
+      return ymdToUnixDate(year, month, day);
     default:
       throw new AssertionError(range);
     }
diff --git a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
index 271de2c..5043467 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
@@ -907,12 +907,41 @@ public class DateTimeUtilsTest {
     final long y1900_0102 = y1900 + 1;
     final long y1899 = y1900 - 365;
     final long y1901 = y1900 + 365;
+    final long y1900_0506 = y1900 - 1 + 31 + 28 + 31 + 30 + 6; // sunday
+    final long y1900_0512 = y1900 - 1 + 31 + 28 + 31 + 30 + 12; // saturday
+    final long y1900_0513 = y1900 - 1 + 31 + 28 + 31 + 30 + 13; // sunday
+    final long y1900_0514 = y1900 - 1 + 31 + 28 + 31 + 30 + 14; // monday
+    final long y1900_0520 = y1900 - 1 + 31 + 28 + 31 + 30 + 20; // sunday
+    final long y1900_0401 = y1900 - 1 + 31 + 28 + 31 + 1;
+    final long y1900_0501 = y1900 - 1 + 31 + 28 + 31 + 30 + 1;
+    final long y1900_0601 = y1900 - 1 + 31 + 28 + 31 + 30 + 31 + 1;
+    final long y1900_0701 = y1900 - 1 + 31 + 28 + 31 + 30 + 31 + 30 + 1;
+    final long y1900_1001 = y1900 - 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 1;
+    final long y1900_1002 = y1900 - 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 2;
     checkDateString("1900-01-01", (int) y1900);
     checkDateString("1900-01-02", (int) y1900_0102);
     checkDateString("1899-01-01", (int) y1899);
     checkDateString("1901-01-01", (int) y1901);
     assertThat(unixDateFloor(TimeUnitRange.YEAR, y1900_0102), is(y1900));
     assertThat(unixDateCeil(TimeUnitRange.YEAR, y1900_0102), is(y1901));
+    assertThat(unixDateFloor(TimeUnitRange.QUARTER, y1900_0514), is(y1900_0401));
+    assertThat(unixDateCeil(TimeUnitRange.QUARTER, y1900_0514), is(y1900_0701));
+    assertThat(unixDateFloor(TimeUnitRange.QUARTER, y1900_1001), is(y1900_1001));
+    assertThat(unixDateCeil(TimeUnitRange.QUARTER, y1900_1001), is(y1900_1001));
+    assertThat(unixDateFloor(TimeUnitRange.QUARTER, y1900_1002), is(y1900_1001));
+    assertThat(unixDateCeil(TimeUnitRange.QUARTER, y1900_1002), is(y1901));
+    assertThat(unixDateFloor(TimeUnitRange.MONTH, y1900_0514), is(y1900_0501));
+    assertThat(unixDateCeil(TimeUnitRange.MONTH, y1900_0514), is(y1900_0601));
+    assertThat(unixDateFloor(TimeUnitRange.WEEK, y1900_0514), is(y1900_0513));
+    assertThat(unixDateCeil(TimeUnitRange.WEEK, y1900_0514), is(y1900_0520));
+    assertThat(unixDateFloor(TimeUnitRange.WEEK, y1900_0514), is(y1900_0513));
+    assertThat(unixDateCeil(TimeUnitRange.WEEK, y1900_0514), is(y1900_0520));
+    assertThat(unixDateFloor(TimeUnitRange.WEEK, y1900_0513), is(y1900_0513));
+    assertThat(unixDateCeil(TimeUnitRange.WEEK, y1900_0513), is(y1900_0513));
+    assertThat(unixDateFloor(TimeUnitRange.WEEK, y1900_0512), is(y1900_0506));
+    assertThat(unixDateCeil(TimeUnitRange.WEEK, y1900_0512), is(y1900_0513));
+    assertThat(unixDateFloor(TimeUnitRange.DAY, y1900_0514), is(y1900_0514));
+    assertThat(unixDateCeil(TimeUnitRange.DAY, y1900_0514), is(y1900_0514));
   }
 }
 


[calcite-avatica] 01/03: [CALCITE-3199] DateTimeUtils.unixDateCeil should not return the same value as unixDateFloor (Zhenghua Gao)

Posted by jh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git

commit be246b9c5c3e2662be723147ae8aa3e3730a4d13
Author: Zhenghua Gao <do...@gmail.com>
AuthorDate: Tue Jul 16 17:58:10 2019 +0800

    [CALCITE-3199] DateTimeUtils.unixDateCeil should not return the same value as unixDateFloor (Zhenghua Gao)
    
    Close apache/calcite-avatica#109
---
 .../org/apache/calcite/avatica/util/DateTimeUtils.java    |  2 +-
 .../apache/calcite/avatica/util/DateTimeUtilsTest.java    | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
index e028a81..5efa210 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java
@@ -893,7 +893,7 @@ public class DateTimeUtils {
   }
 
   public static long unixDateCeil(TimeUnitRange range, long date) {
-    return julianDateFloor(range, (int) date + EPOCH_JULIAN, true);
+    return julianDateFloor(range, (int) date + EPOCH_JULIAN, false);
   }
 
   private static int julianDateFloor(TimeUnitRange range, int julian,
diff --git a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
index 7dbfaba..271de2c 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
@@ -34,7 +34,9 @@ import static org.apache.calcite.avatica.util.DateTimeUtils.intervalYearMonthToS
 import static org.apache.calcite.avatica.util.DateTimeUtils.subtractMonths;
 import static org.apache.calcite.avatica.util.DateTimeUtils.timeStringToUnixDate;
 import static org.apache.calcite.avatica.util.DateTimeUtils.timestampStringToUnixDate;
+import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateCeil;
 import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateExtract;
+import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateFloor;
 import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateToString;
 import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimeExtract;
 import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimeToString;
@@ -899,6 +901,19 @@ public class DateTimeUtilsTest {
     assertThat(pt2.getCalendar().get(Calendar.MILLISECOND), is(60));
     assertThat(pt2.getFraction(), is("06"));
   }
+
+  @Test public void testUnixDateFloorCeil() {
+    final long y1900 = -(70 * 365 + 70 / 4);
+    final long y1900_0102 = y1900 + 1;
+    final long y1899 = y1900 - 365;
+    final long y1901 = y1900 + 365;
+    checkDateString("1900-01-01", (int) y1900);
+    checkDateString("1900-01-02", (int) y1900_0102);
+    checkDateString("1899-01-01", (int) y1899);
+    checkDateString("1901-01-01", (int) y1901);
+    assertThat(unixDateFloor(TimeUnitRange.YEAR, y1900_0102), is(y1900));
+    assertThat(unixDateCeil(TimeUnitRange.YEAR, y1900_0102), is(y1901));
+  }
 }
 
 // End DateTimeUtilsTest.java