Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1a15f53
udf: replace function
Aug 13, 2020
7d072b9
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 14, 2020
391158f
udf: replace function
Aug 14, 2020
5eb52e1
udf: replace function
Aug 14, 2020
a79ea91
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 18, 2020
86f841f
udf: replace function
Aug 18, 2020
ade1afa
udf: replace function
Aug 18, 2020
1d95a49
udf: replace function
Aug 18, 2020
433eb87
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 24, 2020
c62d239
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 25, 2020
0a8db8c
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 25, 2020
02d3f86
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 1, 2020
41da0ba
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 8, 2020
de4e523
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 11, 2020
a863b0d
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 17, 2020
024c422
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 22, 2020
e1656c7
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 23, 2020
837e037
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 27, 2020
a36d3e7
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 17, 2020
43cfa2b
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 23, 2020
641efb5
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 24, 2020
5066131
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 26, 2020
dde044b
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 27, 2020
3cab43f
cast int type to date type
Oct 27, 2020
25003d1
cast int type to date type
Oct 27, 2020
842b25f
cast int type to date type
Oct 27, 2020
67aa616
Merge remote-tracking branch 'upstream/master' into cast_intdate_to_d…
Oct 28, 2020
f2a9dca
update
Oct 28, 2020
f2ddf0d
Merge remote-tracking branch 'upstream/master' into cast_intdate_to_d…
Oct 29, 2020
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
20 changes: 20 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,10 @@ public static Type getCmpType(Type t1, Type t2) {

PrimitiveType t1ResultType = t1.getResultType().getPrimitiveType();
PrimitiveType t2ResultType = t2.getResultType().getPrimitiveType();
if (canCompareDate(t1.getPrimitiveType(), t2.getPrimitiveType())) {
return Type.DATETIME;
}

// Following logical is compatible with MySQL.
if ((t1ResultType == PrimitiveType.VARCHAR && t2ResultType == PrimitiveType.VARCHAR)) {
return Type.VARCHAR;
Expand Down Expand Up @@ -1007,6 +1011,22 @@ public static Type getCmpType(Type t1, Type t2) {
return Type.DOUBLE;
}

public static boolean canCompareDate(PrimitiveType t1, PrimitiveType t2) {
if (t1.isDateType()) {
if (t2.isDateType() || t2.isStringType() || t2.isIntegerType()) {
return true;
}
return false;
} else if (t2.isDateType()) {
if (t1.isStringType() || t1.isIntegerType()) {
return true;
}
return false;
} else {
return false;
}
}

public Type getMaxResolutionType() {
Preconditions.checkState(true, "must implemented");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ public static void beforeClass() throws Exception {
"\"driver\" = \"Oracle Driver\",\n" +
"\"odbc_type\" = \"mysql\"\n" +
");");

createTable("create table test.tbl_int_date (" +
"`date` datetime NULL," +
"`day` date NULL," +
"`site_id` int(11) NULL )" +
" ENGINE=OLAP " +
"DUPLICATE KEY(`date`, `day`, `site_id`)" +
"DISTRIBUTED BY HASH(`site_id`) BUCKETS 10 " +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\",\n" +
"\"in_memory\" = \"false\",\n" +
"\"storage_format\" = \"V2\"\n" +
");");
}

@AfterClass
Expand Down Expand Up @@ -1318,7 +1331,6 @@ public void testAggregateSatisfyOlapTableDistribution() throws Exception {
Assert.assertTrue(explainString.contains("AGGREGATE (update finalize)"));
}

@Test
public void testLeadAndLagFunction() throws Exception {
connectContext.setDatabase("default_cluster:test");

Expand All @@ -1338,6 +1350,37 @@ public void testLeadAndLagFunction() throws Exception {
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
Assert.assertTrue(explainString.contains("lag(`query_time`, 1, 2)"));
}

@Test
public void testIntDateTime() throws Exception {
connectContext.setDatabase("default_cluster:test");
//valid date
String sql = "select day from tbl_int_date where day in ('2020-10-30')";
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `day` IN ('2020-10-30 00:00:00')"));
//valid date
sql = "select day from tbl_int_date where day in ('2020-10-30','2020-10-29')";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `day` IN ('2020-10-30 00:00:00', '2020-10-29 00:00:00')"));

//valid datetime
sql = "select day from tbl_int_date where date in ('2020-10-30 12:12:30')";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 12:12:30')"));
//valid datetime
sql = "select day from tbl_int_date where date in ('2020-10-30')";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 00:00:00')"));

//int date
sql = "select day from tbl_int_date where day in (20201030)";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `day` IN ('2020-10-30 00:00:00')"));
//int datetime
sql = "select day from tbl_int_date where date in (20201030)";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 00:00:00')"));
}
}