Code review comment: We should be break if we met a floating point type column. The following case will get wrong result in your logic:  `k1 int, k2 float, k3 int`

Code before review:
private void analyzeOrderByClause() throws AnalysisException {
if (selectStmt.getOrderByElements() == null) {
/**
* The keys type of Materialized view is aggregation.
* All of group by columns are keys of materialized view.
*/
if (mvKeysType == KeysType.AGG_KEYS) {
for (MVColumnItem mvColumnItem : mvColumnItemList) {
if (mvColumnItem.getAggregationType() != null) {
break;
}
if (mvColumnItem.getType().isFloatingPointType()) {
throw new AnalysisException("Float or double can not used as a key, use decimal instead.");
}
mvColumnItem.setIsKey(true);
}
return;
}
/**
* There is no aggregation function in materialized view.
* Supplement key of MV columns
* For example: select k1, k2 ... kn from t1
* The default key columns are first 36 bytes of the columns in define order.
* If the number of columns in the first 36 is less than 3, the first 3 columns will be used.
* column: k1, k2, k3... km. The key is true.
* Supplement non-key of MV columns
* column: km... kn. The key is false, aggregation type is none, isAggregationTypeImplicit is true.
*/
int keyStorageLayoutBytes = 0;
for (int i = 0; i < selectStmt.getResultExprs().size(); i++) {
MVColumnItem mvColumnItem = mvColumnItemList.get(i);
Expr resultColumn = selectStmt.getResultExprs().get(i);
keyStorageLayoutBytes += resultColumn.getType().getStorageLayoutBytes();
if ((!mvColumnItem.getType().isFloatingPointType())
&& ((i + 1) <= FeConstants.shortkey_max_column_count
|| keyStorageLayoutBytes < FeConstants.shortkey_maxsize_bytes)) {
mvColumnItem.setIsKey(true);
} else {
if (i == 0) {
throw new AnalysisException("The first column could not be float or double, "
+ "use decimal instead.");
}
mvColumnItem.setAggregationType(AggregateType.NONE, true);
}
}
return;
}
List<OrderByElement> 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");
}
if (beginIndexOfAggregation != -1 && (orderByElements.size() != (beginIndexOfAggregation))) {
throw new AnalysisException("The key of columns in mv must be all of group by columns");
}
for (int i = 0; i < orderByElements.size(); i++) {
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());
}
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");
}
Preconditions.checkState(mvColumnItem.getAggregationType() == null);
mvColumnItem.setIsKey(true);
}
for (MVColumnItem mvColumnItem : mvColumnItemList) {
if (mvColumnItem.isKey()) {
continue;
}
if (mvColumnItem.getAggregationType() != null) {
break;
}
mvColumnItem.setAggregationType(AggregateType.NONE, true);
}
}

Line under review: if ((!mvColumnItem.getType().isFloatingPointType())

Code after addressing the review:
private void analyzeOrderByClause() throws AnalysisException {
if (selectStmt.getOrderByElements() == null) {
supplyOrderColumn();
return;
}
List<OrderByElement> 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");
}
if (beginIndexOfAggregation != -1 && (orderByElements.size() != (beginIndexOfAggregation))) {
throw new AnalysisException("The key of columns in mv must be all of group by columns");
}
for (int i = 0; i < orderByElements.size(); i++) {
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());
}
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");
}
Preconditions.checkState(mvColumnItem.getAggregationType() == null);
mvColumnItem.setIsKey(true);
}
for (MVColumnItem mvColumnItem : mvColumnItemList) {
if (mvColumnItem.isKey()) {
continue;
}
if (mvColumnItem.getAggregationType() != null) {
break;
}
mvColumnItem.setAggregationType(AggregateType.NONE, true);
}
}