-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drill-specific changes: added a general class for Date/Time/Timestamp…
… literals (TimestampString, DateString, TimeString) to avoid class cast exceptions. In case of "date + interval" situation, for example: where o.o_orderdate >= date '1996-10-01' and o.o_orderdate < date '1996-10-01' + interval '3' month Drill will cast DATE to TIMESTAMP and we can face with ClassCastException like "ClassCastException: org.apache.calcite.util.DateString cannot be cast to org.apache.calcite.util.TimestampString" when Calcite will compare DATE ('1996-10-01') with TIMESTAMP ('1996-10-01' + interval '3'). To avoid this situation added a general class for Date/Time/Timestamp literals to make them comparable to each other. Also added comparing NlsString with Date/Time/Timestamp strings to avoid ClassCastExceptoin in queries like: WHERE birth_date BETWEEN '1920-01-01' AND cast('1931-01-01' AS DATE) In this case, '1920-01-01' is NlsString and we got ClassCastExceptoin when we tried to compare it with Date '1931-01-01'. (cherry picked from commit afd4fc6) (cherry picked from commit 6e793d4)
- Loading branch information
1 parent
b912229
commit 029d02d
Showing
5 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
core/src/main/java/org/apache/calcite/util/AbstractDateTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.calcite.util; | ||
|
||
/** | ||
* General class for Date/Time/Timestamp literals (TimestampString, DateString, TimeString) | ||
* to make them comparable to each other | ||
*/ | ||
public abstract class AbstractDateTime implements Comparable { | ||
protected final String v; | ||
|
||
public AbstractDateTime(String v) { | ||
this.v = v; | ||
} | ||
|
||
@Override public int compareTo(Object o) { | ||
if (o instanceof NlsString) { | ||
return v.compareTo(((NlsString) o).getValue()); | ||
} | ||
return v.compareTo(((AbstractDateTime) o).v); | ||
} | ||
} | ||
|
||
// End AbstractDateTime.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters