Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AL-6695 cast date to timestamp when date compare with timestamp #298

Open
wants to merge 1 commit into
base: kycalcite-spark3-1.16.0.x-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-cassandra</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Cassandra</name>
<description>Cassandra adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-core</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Core</name>
<description>Core Calcite APIs and engine.</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.calcite.rex.RexCall;
import org.apache.calcite.rex.RexCallBinding;
import org.apache.calcite.rex.RexDynamicParam;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexRangeRef;
Expand Down Expand Up @@ -859,7 +860,7 @@ public static List<RexNode> convertExpressionList(SqlRexContext cx,
}
if (exprs.size() > 1) {
RelDataType type =
consistentType(cx, consistency, RexUtil.types(exprs));
consistentType(cx, consistency, RexUtil.types(exprs), exprs);

/* OVERRIDE POINT */
if (type == null) {
Expand Down Expand Up @@ -907,9 +908,14 @@ private static RelDataType consistentType2(SqlRexContext cx,
}

private static RelDataType consistentType(SqlRexContext cx,
SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) {
SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types, List<RexNode> exprs) {
switch (consistency) {
case COMPARE:
if (Boolean.parseBoolean(
System.getProperty("calcite.convert-date-to-timeStamp-enabled", "false"))
&& isDateCompareWithTimeStamp(types, exprs)) {
return castDateToTimeStamp(types);
}
final Set<RelDataTypeFamily> families =
Sets.newHashSet(RexUtil.families(types));
if (families.size() < 2) {
Expand Down Expand Up @@ -946,6 +952,11 @@ private static RelDataType consistentType(SqlRexContext cx,
/* OVERRIDE POINT */
//https://github.com/Kyligence/KAP/issues/13872
case LEAST_RESTRICTIVE_NO_CONVERT_TO_VARYING:
if (Boolean.parseBoolean(
System.getProperty("calcite.convert-date-to-timeStamp-enabled", "false"))
&& isDateCompareWithTimeStamp(types, exprs)) {
return castDateToTimeStamp(types);
}
return cx.getTypeFactory().leastRestrictive(types, false);
default:
return null;
Expand Down Expand Up @@ -988,6 +999,33 @@ private RexNode convertPlus(SqlRexContext cx, SqlCall call) {
}
}

public static boolean isDateCompareWithTimeStamp(List<RelDataType> types, List<RexNode> exprs) {

if (types.size() != 2 || exprs.size() != 2) {
return false;
}

RelDataType leftType = types.get(0);
RelDataType rightType = types.get(1);

RexNode leftNode = exprs.get(0);
RexNode rightNode = exprs.get(1);

if (leftNode instanceof RexInputRef && rightNode instanceof RexLiteral) {
return leftType.getFamily().equals(SqlTypeFamily.TIMESTAMP)
&& rightType.getFamily().equals(SqlTypeFamily.DATE);
}
if (leftNode instanceof RexLiteral && rightNode instanceof RexInputRef) {
return leftType.getFamily().equals(SqlTypeFamily.DATE)
&& rightType.getFamily().equals(SqlTypeFamily.TIMESTAMP);
}
return false;
}

public static RelDataType castDateToTimeStamp(List<RelDataType> types) {
return types.get(0).getFamily().equals(SqlTypeFamily.TIMESTAMP) ? types.get(0) : types.get(1);
}

private RexNode convertIsDistinctFrom(
SqlRexContext cx,
SqlCall call,
Expand Down
4 changes: 2 additions & 2 deletions druid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-druid</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Druid</name>
<description>Druid adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-elasticsearch2</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Elasticsearch</name>
<description>Elasticsearch adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-elasticsearch5</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Elasticsearch5</name>
<description>Elasticsearch5 adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions example/csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-example</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-example-csv</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Example CSV</name>
<description>An example Calcite provider that reads CSV files</description>

Expand Down
4 changes: 2 additions & 2 deletions example/function/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-example</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-example-function</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Example Function</name>
<description>Examples of user-defined Calcite functions</description>

Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<!-- The basics. -->
<artifactId>calcite-example</artifactId>
<packaging>pom</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Examples</name>
<description>Calcite examples</description>

Expand Down
4 changes: 2 additions & 2 deletions file/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<!-- The basics. -->
<artifactId>calcite-file</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite File</name>
<description>Calcite provider that reads files and URIs</description>

Expand Down
4 changes: 2 additions & 2 deletions geode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-geode</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Geode</name>
<description>Geode adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions linq4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-linq4j</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Linq4j</name>
<description>Calcite APIs for LINQ (Language-Integrated Query) in Java</description>

Expand Down
4 changes: 2 additions & 2 deletions mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-mongodb</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite MongoDB</name>
<description>MongoDB adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions pig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version></parent>
<version>1.116.0-kylin-4.x-r024</version></parent>

<artifactId>calcite-pig</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Pig</name>
<description>Pig adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions piglet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-piglet</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Piglet</name>
<description>Pig-like language built on top of Calcite algebra</description>

Expand Down
4 changes: 2 additions & 2 deletions plus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-plus</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Plus</name>
<description>Miscellaneous extras for Calcite</description>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ limitations under the License.
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<packaging>pom</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>

<!-- More project information. -->
<name>Calcite</name>
Expand Down
4 changes: 2 additions & 2 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-server</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Server</name>
<description>Calcite Server</description>

Expand Down
4 changes: 2 additions & 2 deletions spark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-spark</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Spark</name>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions splunk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-splunk</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Splunk</name>
<description>Splunk adapter for Calcite; also a JDBC driver for Splunk</description>

Expand Down
2 changes: 1 addition & 1 deletion ubenchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<properties>
Expand Down