From 4d94f36748c47a529b6a3c9e21f0df2e125d22ab Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Mon, 27 Jul 2020 16:58:57 +0800
Subject: [PATCH 1/7] Change type of sum, min, max function column in mv
If the agg function is sum, the type of mv column will be bigint.
The only exception is that if the base column is largeint, the type of mv column will be largeint.
If the agg function is min or max, the type of mv column will be same as the type of base column.
For example, the type of mv column is smallint when the agg function is min.
Change-Id: I1b541fd03342ceba093c4aabd8a29793c52781dc
---
.../analysis/CreateMaterializedViewStmt.java | 51 ++++++++++---------
.../apache/doris/analysis/MVColumnItem.java | 1 +
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 35a00e7cd2d139..5fc867ed3a2fe7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -17,6 +17,10 @@
package org.apache.doris.analysis;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.KeysType;
@@ -30,11 +34,6 @@
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -47,10 +46,10 @@
*
* Syntax:
* CREATE MATERIALIZED VIEW [MV name] (
- * SELECT select_expr[, select_expr ...]
- * FROM [Base view name]
- * GROUP BY column_name[, column_name ...]
- * ORDER BY column_name[, column_name ...])
+ * SELECT select_expr[, select_expr ...]
+ * FROM [Base view name]
+ * GROUP BY column_name[, column_name ...]
+ * ORDER BY column_name[, column_name ...])
* [PROPERTIES ("key" = "value")]
*/
public class CreateMaterializedViewStmt extends DdlStmt {
@@ -60,11 +59,11 @@ public class CreateMaterializedViewStmt extends DdlStmt {
static {
FN_NAME_TO_PATTERN = Maps.newHashMap();
FN_NAME_TO_PATTERN.put(AggregateType.SUM.name().toLowerCase(),
- new MVColumnOneChildPattern(AggregateType.SUM.name().toLowerCase()));
+ new MVColumnOneChildPattern(AggregateType.SUM.name().toLowerCase()));
FN_NAME_TO_PATTERN.put(AggregateType.MIN.name().toLowerCase(),
- new MVColumnOneChildPattern(AggregateType.MIN.name().toLowerCase()));
+ new MVColumnOneChildPattern(AggregateType.MIN.name().toLowerCase()));
FN_NAME_TO_PATTERN.put(AggregateType.MAX.name().toLowerCase(),
- new MVColumnOneChildPattern(AggregateType.MAX.name().toLowerCase()));
+ new MVColumnOneChildPattern(AggregateType.MAX.name().toLowerCase()));
FN_NAME_TO_PATTERN.put(FunctionSet.COUNT, new MVColumnOneChildPattern(FunctionSet.COUNT));
FN_NAME_TO_PATTERN.put(FunctionSet.BITMAP_UNION, new MVColumnBitmapUnionPattern());
FN_NAME_TO_PATTERN.put(FunctionSet.HLL_UNION, new MVColumnHLLUnionPattern());
@@ -78,9 +77,9 @@ public class CreateMaterializedViewStmt extends DdlStmt {
/**
* origin stmt: select k1, k2, v1, sum(v2) from base_table group by k1, k2, v1
* mvColumnItemList: [k1: {name: k1, isKey: true, aggType: null, isAggregationTypeImplicit: false},
- * k2: {name: k2, isKey: true, aggType: null, isAggregationTypeImplicit: false},
- * v1: {name: v1, isKey: true, aggType: null, isAggregationTypeImplicit: false},
- * v2: {name: v2, isKey: false, aggType: sum, isAggregationTypeImplicit: false}]
+ * k2: {name: k2, isKey: true, aggType: null, isAggregationTypeImplicit: false},
+ * v1: {name: v1, isKey: true, aggType: null, isAggregationTypeImplicit: false},
+ * v2: {name: v2, isKey: false, aggType: sum, isAggregationTypeImplicit: false}]
* This order of mvColumnItemList is meaningful.
*/
private List mvColumnItemList = Lists.newArrayList();
@@ -139,16 +138,16 @@ public void analyze(Analyzer analyzer) throws UserException {
analyzeFromClause();
if (selectStmt.getWhereClause() != null) {
throw new AnalysisException("The where clause is not supported in add materialized view clause, expr:"
- + selectStmt.getWhereClause().toSql());
+ + selectStmt.getWhereClause().toSql());
}
if (selectStmt.getHavingPred() != null) {
throw new AnalysisException("The having clause is not supported in add materialized view clause, expr:"
- + selectStmt.getHavingPred().toSql());
+ + selectStmt.getHavingPred().toSql());
}
analyzeOrderByClause();
if (selectStmt.getLimit() != -1) {
throw new AnalysisException("The limit clause is not supported in add materialized view clause, expr:"
- + " limit " + selectStmt.getLimit());
+ + " limit " + selectStmt.getLimit());
}
}
@@ -174,7 +173,7 @@ public void analyzeSelectClause() throws AnalysisException {
Expr selectListItemExpr = selectListItem.getExpr();
if (!(selectListItemExpr instanceof SlotRef) && !(selectListItemExpr instanceof FunctionCallExpr)) {
throw new AnalysisException("The materialized view only support the single column or function expr. "
- + "Error column: " + selectListItemExpr.toSql());
+ + "Error column: " + selectListItemExpr.toSql());
}
if (selectListItemExpr instanceof SlotRef) {
if (meetAggregate) {
@@ -245,7 +244,7 @@ private void analyzeOrderByClause() throws AnalysisException {
List orderByElements = selectStmt.getOrderByElements();
if (orderByElements.size() > mvColumnItemList.size()) {
throw new AnalysisException("The number of columns in order clause must be less then " + "the number of "
- + "columns in select clause");
+ + "columns in select clause");
}
if (beginIndexOfAggregation != -1 && (orderByElements.size() != (beginIndexOfAggregation))) {
throw new AnalysisException("The key of columns in mv must be all of group by columns");
@@ -254,13 +253,13 @@ private void analyzeOrderByClause() throws AnalysisException {
Expr orderByElement = orderByElements.get(i).getExpr();
if (!(orderByElement instanceof SlotRef)) {
throw new AnalysisException("The column in order clause must be original column without calculation. "
- + "Error column: " + orderByElement.toSql());
+ + "Error column: " + orderByElement.toSql());
}
MVColumnItem mvColumnItem = mvColumnItemList.get(i);
SlotRef slotRef = (SlotRef) orderByElement;
if (!mvColumnItem.getName().equalsIgnoreCase(slotRef.getColumnName())) {
throw new AnalysisException("The order of columns in order by clause must be same as "
- + "the order of columns in select list");
+ + "the order of columns in select list");
}
Preconditions.checkState(mvColumnItem.getAggregationType() == null);
mvColumnItem.setIsKey(true);
@@ -353,11 +352,15 @@ public MVColumnItem buildMVColumnItem(FunctionCallExpr functionCallExpr) throws
Type type;
switch (functionName.toLowerCase()) {
case "sum":
+ mvColumnName = baseColumnName;
+ mvAggregateType = AggregateType.valueOf(functionName.toUpperCase());
+ type = baseColumnRef.getType().getPrimitiveType() == PrimitiveType.LARGEINT ? Type.LARGEINT : Type.BIGINT;
+ break;
case "min":
case "max":
mvColumnName = baseColumnName;
mvAggregateType = AggregateType.valueOf(functionName.toUpperCase());
- type = Type.BIGINT;
+ type = Type.fromPrimitiveType(baseColumnRef.getType().getPrimitiveType());
break;
case FunctionSet.BITMAP_UNION:
// Compatible aggregation models
@@ -445,7 +448,7 @@ public Map parseDefineExprWithoutAnalyze() throws AnalysisExceptio
case FunctionSet.COUNT:
Expr defineExpr = new CaseExpr(null, Lists.newArrayList(
new CaseWhenClause(new IsNullPredicate(slots.get(0), false),
- new IntLiteral(0, Type.BIGINT))), new IntLiteral(1, Type.BIGINT));
+ new IntLiteral(0, Type.BIGINT))), new IntLiteral(1, Type.BIGINT));
result.put(mvColumnBuilder(functionName, baseColumnName), defineExpr);
break;
default:
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/MVColumnItem.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/MVColumnItem.java
index 55762cbbd1ab00..37137e4710d6ab 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/MVColumnItem.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/MVColumnItem.java
@@ -105,6 +105,7 @@ public Column toMVColumn(OlapTable olapTable) throws DdlException {
} else {
Column result = new Column(baseColumn);
result.setIsKey(isKey);
+ result.setType(type);
result.setAggregationType(aggregationType, isAggregationTypeImplicit);
return result;
}
From caebfc742e5bebed36929329af6dbe4f5552664a Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Tue, 28 Jul 2020 18:03:51 +0800
Subject: [PATCH 2/7] Add unit test
Change-Id: Id451b0f7b334e265e1b495ee0aa47a686fffc1ee
---
.../analysis/CreateMaterializedViewStmt.java | 2 +-
.../CreateMaterializedViewStmtTest.java | 76 +++++++++++++------
2 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 5fc867ed3a2fe7..5f19f9e03db130 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -338,7 +338,7 @@ private void supplyOrderColumn() throws AnalysisException {
}
}
- public MVColumnItem buildMVColumnItem(FunctionCallExpr functionCallExpr) throws AnalysisException {
+ private MVColumnItem buildMVColumnItem(FunctionCallExpr functionCallExpr) throws AnalysisException {
String functionName = functionCallExpr.getFnName().getFunction();
List slots = new ArrayList<>();
functionCallExpr.collect(SlotRef.class, slots);
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
index da42668fefa06e..95e8716b3f8788 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
@@ -17,16 +17,18 @@
package org.apache.doris.analysis;
+import com.google.common.collect.Lists;
+import mockit.Expectations;
+import mockit.Injectable;
+import mockit.Mocked;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.Type;
import org.apache.doris.common.Config;
import org.apache.doris.common.UserException;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.qe.ConnectContext;
-
-import com.google.common.collect.Lists;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -34,10 +36,6 @@
import java.util.ArrayList;
import java.util.List;
-import mockit.Expectations;
-import mockit.Injectable;
-import mockit.Mocked;
-
public class CreateMaterializedViewStmtTest {
@Mocked
@@ -325,7 +323,7 @@ public void testDuplicateColumn(@Injectable SelectStmt selectStmt) throws UserEx
@Test
public void testDuplicateColumn1(@Injectable SlotRef slotRef1,
- @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -415,7 +413,7 @@ public void testMVColumnsWithoutOrderby(@Injectable SlotRef slotRef1,
@Injectable SlotRef slotRef4,
@Injectable TableRef tableRef,
@Injectable SelectStmt selectStmt,
- @Injectable AggregateInfo aggregateInfo) throws UserException {
+ @Injectable AggregateInfo aggregateInfo) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -506,8 +504,8 @@ public void testMVColumnsWithoutOrderby(@Injectable SlotRef slotRef1,
@Test
public void testMVColumnsWithoutOrderbyWithoutAggregation(@Injectable SlotRef slotRef1,
- @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
- @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
+ @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -606,8 +604,8 @@ public void testMVColumnsWithoutOrderbyWithoutAggregation(@Injectable SlotRef sl
*/
@Test
public void testMVColumnsWithoutOrderbyWithoutAggregationWithFloat(@Injectable SlotRef slotRef1,
- @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
- @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
+ @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -704,8 +702,8 @@ public void testMVColumnsWithoutOrderbyWithoutAggregationWithFloat(@Injectable S
*/
@Test
public void testMVColumnsWithoutOrderbyWithoutAggregationWithVarchar(@Injectable SlotRef slotRef1,
- @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
- @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable SlotRef slotRef2, @Injectable SlotRef slotRef3, @Injectable SlotRef slotRef4,
+ @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -802,7 +800,7 @@ public void testMVColumnsWithoutOrderbyWithoutAggregationWithVarchar(@Injectable
*/
@Test
public void testMVColumnsWithFirstFloat(@Injectable SlotRef slotRef1,
- @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -850,7 +848,7 @@ public void testMVColumnsWithFirstFloat(@Injectable SlotRef slotRef1,
*/
@Test
public void testMVColumnsWithFirstVarchar(@Injectable SlotRef slotRef1,
- @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
+ @Injectable TableRef tableRef, @Injectable SelectStmt selectStmt) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -903,10 +901,10 @@ public void testMVColumnsWithFirstVarchar(@Injectable SlotRef slotRef1,
@Test
public void testMVColumns(@Injectable SlotRef slotRef1,
- @Injectable SlotRef slotRef2,
- @Injectable TableRef tableRef,
- @Injectable SelectStmt selectStmt,
- @Injectable AggregateInfo aggregateInfo) throws UserException {
+ @Injectable SlotRef slotRef2,
+ @Injectable TableRef tableRef,
+ @Injectable SelectStmt selectStmt,
+ @Injectable AggregateInfo aggregateInfo) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -981,9 +979,9 @@ public void testMVColumns(@Injectable SlotRef slotRef1,
@Test
public void testDeduplicateMV(@Injectable SlotRef slotRef1,
- @Injectable TableRef tableRef,
- @Injectable SelectStmt selectStmt,
- @Injectable AggregateInfo aggregateInfo) throws UserException {
+ @Injectable TableRef tableRef,
+ @Injectable SelectStmt selectStmt,
+ @Injectable AggregateInfo aggregateInfo) throws UserException {
SelectList selectList = new SelectList();
SelectListItem selectListItem1 = new SelectListItem(slotRef1, null);
selectList.addItem(selectListItem1);
@@ -1022,5 +1020,35 @@ public void testDeduplicateMV(@Injectable SlotRef slotRef1,
}
}
+
+ @Test
+ public void testBuildMVColumnItem(@Injectable SelectStmt selectStmt) {
+ CreateMaterializedViewStmt createMaterializedViewStmt = new CreateMaterializedViewStmt("test", selectStmt, null);
+ SlotRef slotRef = new SlotRef(new TableName("db", "table"), "a");
+ List params = Lists.newArrayList();
+ params.add(slotRef);
+ FunctionCallExpr functionCallExpr = new FunctionCallExpr("sum", params);
+ slotRef.setType(Type.LARGEINT);
+ MVColumnItem mvColumnItem = Deencapsulation.invoke(createMaterializedViewStmt, "buildMVColumnItem", functionCallExpr);
+ Assert.assertEquals(Type.LARGEINT, mvColumnItem.getType());
+
+ SlotRef slotRef2 = new SlotRef(new TableName("db", "table"), "a");
+ List params2 = Lists.newArrayList();
+ params2.add(slotRef2);
+ FunctionCallExpr functionCallExpr2 = new FunctionCallExpr("sum", params2);
+ slotRef2.setType(Type.SMALLINT);
+ MVColumnItem mvColumnItem2 = Deencapsulation.invoke(createMaterializedViewStmt, "buildMVColumnItem", functionCallExpr2);
+ Assert.assertEquals(Type.BIGINT, mvColumnItem2.getType());
+
+ SlotRef slotRef3 = new SlotRef(new TableName("db", "table"), "a");
+ List params3 = Lists.newArrayList();
+ params3.add(slotRef3);
+ FunctionCallExpr functionCallExpr3 = new FunctionCallExpr("min", params2);
+ slotRef2.setType(Type.VARCHAR);
+ MVColumnItem mvColumnItem3 = Deencapsulation.invoke(createMaterializedViewStmt, "buildMVColumnItem", functionCallExpr3);
+ Assert.assertEquals(Type.VARCHAR, mvColumnItem3.getType());
+
+
+ }
}
From 9a7ab502e005d87b476f6cc7c369993f1745cd6a Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Tue, 28 Jul 2020 18:12:40 +0800
Subject: [PATCH 3/7] Change import sequence
Change-Id: Iffb7d3d7cbac6e98f4f358dd7c98a7d0dea2d4fc
---
.../doris/analysis/CreateMaterializedViewStmt.java | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 5f19f9e03db130..065955fc767f60 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -17,10 +17,16 @@
package org.apache.doris.analysis;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.KeysType;
@@ -34,11 +40,6 @@
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* Materialized view is performed to materialize the results of query.
* This clause is used to create a new materialized view for a specified table
From f107770f4a4e7f5c1205cbbc43bb843cd78b4cf1 Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Tue, 28 Jul 2020 20:14:07 +0800
Subject: [PATCH 4/7] If the type of base column is tinyint, smallint or int,
the type of mv column will be bigint. Otherwise, the type of mv column is
same as the type of base column.
Change-Id: I39b869c18a24b2e8506bfbea22be781488132d69
---
.../doris/analysis/CreateMaterializedViewStmt.java | 8 +++++++-
.../analysis/CreateMaterializedViewStmtTest.java | 12 ++++++++++--
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 065955fc767f60..a9b79f1ff6f976 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -355,7 +355,13 @@ private MVColumnItem buildMVColumnItem(FunctionCallExpr functionCallExpr) throws
case "sum":
mvColumnName = baseColumnName;
mvAggregateType = AggregateType.valueOf(functionName.toUpperCase());
- type = baseColumnRef.getType().getPrimitiveType() == PrimitiveType.LARGEINT ? Type.LARGEINT : Type.BIGINT;
+ PrimitiveType baseColumnType = baseColumnRef.getType().getPrimitiveType();
+ if (baseColumnType == PrimitiveType.TINYINT || baseColumnType == PrimitiveType.SMALLINT
+ || baseColumnType == PrimitiveType.INT) {
+ type = Type.BIGINT;
+ } else {
+ type = Type.fromPrimitiveType(baseColumnRef.getType().getPrimitiveType());
+ }
break;
case "min":
case "max":
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
index 95e8716b3f8788..187b089e696694 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
@@ -1043,11 +1043,19 @@ public void testBuildMVColumnItem(@Injectable SelectStmt selectStmt) {
SlotRef slotRef3 = new SlotRef(new TableName("db", "table"), "a");
List params3 = Lists.newArrayList();
params3.add(slotRef3);
- FunctionCallExpr functionCallExpr3 = new FunctionCallExpr("min", params2);
- slotRef2.setType(Type.VARCHAR);
+ FunctionCallExpr functionCallExpr3 = new FunctionCallExpr("min", params3);
+ slotRef3.setType(Type.VARCHAR);
MVColumnItem mvColumnItem3 = Deencapsulation.invoke(createMaterializedViewStmt, "buildMVColumnItem", functionCallExpr3);
Assert.assertEquals(Type.VARCHAR, mvColumnItem3.getType());
+ SlotRef slotRef4 = new SlotRef(new TableName("db", "table"), "a");
+ List params4 = Lists.newArrayList();
+ params4.add(slotRef4);
+ FunctionCallExpr functionCallExpr4 = new FunctionCallExpr("sum", params4);
+ slotRef4.setType(Type.DOUBLE);
+ MVColumnItem mvColumnItem4 = Deencapsulation.invoke(createMaterializedViewStmt, "buildMVColumnItem", functionCallExpr4);
+ Assert.assertEquals(Type.DOUBLE, mvColumnItem4.getType());
+
}
}
From ea5b2d39731f9e1c5f3ef4634fe7c5b201cae559 Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Wed, 29 Jul 2020 10:07:31 +0800
Subject: [PATCH 5/7] float -> double
Change-Id: I14387f5b1a3654e8c9fe9d8f46f78d51a8ab7ce1
---
.../org/apache/doris/analysis/CreateMaterializedViewStmt.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index a9b79f1ff6f976..3a13709f6d3f4e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -359,6 +359,8 @@ private MVColumnItem buildMVColumnItem(FunctionCallExpr functionCallExpr) throws
if (baseColumnType == PrimitiveType.TINYINT || baseColumnType == PrimitiveType.SMALLINT
|| baseColumnType == PrimitiveType.INT) {
type = Type.BIGINT;
+ } else if (baseColumnType == PrimitiveType.FLOAT) {
+ type = Type.DOUBLE;
} else {
type = Type.fromPrimitiveType(baseColumnRef.getType().getPrimitiveType());
}
From 58849a326a7f838fffc10f0c52be1531b5285437 Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Thu, 30 Jul 2020 10:22:12 +0800
Subject: [PATCH 6/7] Import
Change-Id: I0cf85a09417bfd7be2ec48c42edaf67a8bcef686
---
.../analysis/CreateMaterializedViewStmt.java | 20 +++++++++----------
.../CreateMaterializedViewStmtTest.java | 5 ++++-
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 3a13709f6d3f4e..f9b26f263003df 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -17,16 +17,6 @@
package org.apache.doris.analysis;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.KeysType;
@@ -40,6 +30,16 @@
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Materialized view is performed to materialize the results of query.
* This clause is used to create a new materialized view for a specified table
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
index 187b089e696694..10508d09acfefd 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
@@ -17,10 +17,10 @@
package org.apache.doris.analysis;
-import com.google.common.collect.Lists;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Mocked;
+
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PrimitiveType;
@@ -29,6 +29,9 @@
import org.apache.doris.common.UserException;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.collect.Lists;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
From 7427628d49cc4fbb8e20b3623036d8da27c5dfa3 Mon Sep 17 00:00:00 2001
From: emmymiao87 <522274284@qq.com>
Date: Thu, 30 Jul 2020 10:52:32 +0800
Subject: [PATCH 7/7] Import
Change-Id: I94e76f5b9f5258e81f807c7c5c8b36a451229aaf
---
.../doris/analysis/CreateMaterializedViewStmtTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
index 10508d09acfefd..fdfcec542fab81 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateMaterializedViewStmtTest.java
@@ -17,10 +17,6 @@
package org.apache.doris.analysis;
-import mockit.Expectations;
-import mockit.Injectable;
-import mockit.Mocked;
-
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PrimitiveType;
@@ -39,6 +35,10 @@
import java.util.ArrayList;
import java.util.List;
+import mockit.Expectations;
+import mockit.Injectable;
+import mockit.Mocked;
+
public class CreateMaterializedViewStmtTest {
@Mocked