Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private String assembleCreateMvSqlForDupOrUniqueTable(String baseTableName, Stri
StringBuilder createMvSqlBuilder = new StringBuilder();
createMvSqlBuilder.append(String.format("create materialized view %s as select ", mvName));
for (Column col : columns) {
createMvSqlBuilder.append(String.format("%s, ", col.getName()));
createMvSqlBuilder.append(String.format("%s, ", getIdentSql(col.getName())));
}
removeLastTwoChars(createMvSqlBuilder);
createMvSqlBuilder.append(String.format(" from %s", baseTableName));
Expand Down Expand Up @@ -342,13 +342,13 @@ private String assembleCreateMvSqlForAggTable(String baseTableName, String mvNam
case BITMAP_UNION:
case QUANTILE_UNION: {
aggColumnsStringBuilder
.append(String.format("%s(%s), ", aggregateType, col.getName()));
.append(String.format("%s(%s), ", aggregateType, getIdentSql(col.getName())));
break;
}
case GENERIC: {
AggStateType aggStateType = (AggStateType) col.getType();
aggColumnsStringBuilder.append(String.format("%s_union(%s), ",
aggStateType.getFunctionName(), col.getName()));
aggStateType.getFunctionName(), getIdentSql(col.getName())));
break;
}
default: {
Expand All @@ -362,7 +362,7 @@ private String assembleCreateMvSqlForAggTable(String baseTableName, String mvNam
// use column name for key
Preconditions.checkState(col.isKey(),
String.format("%s must be key", col.getName()));
keyColumnsStringBuilder.append(String.format("%s, ", col.getName()));
keyColumnsStringBuilder.append(String.format("%s, ", getIdentSql(col.getName())));
}
}
Preconditions.checkState(keyColumnsStringBuilder.length() > 0,
Expand All @@ -382,7 +382,7 @@ private String assembleCreateMvSqlForAggTable(String baseTableName, String mvNam
String.format(" from %s group by %s", baseTableName, keyColumnsStringBuilder));
} else {
for (Column col : columns) {
createMvSqlBuilder.append(String.format("%s, ", col.getName()));
createMvSqlBuilder.append(String.format("%s, ", getIdentSql(col.getName())));
}
removeLastTwoChars(createMvSqlBuilder);
createMvSqlBuilder.append(String.format(" from %s", baseTableName));
Expand All @@ -396,4 +396,18 @@ private void removeLastTwoChars(StringBuilder stringBuilder) {
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
}
}

private static String getIdentSql(String ident) {
StringBuilder sb = new StringBuilder();
sb.append('`');
for (char ch : ident.toCharArray()) {
if (ch == '`') {
sb.append("``");
} else {
sb.append(ch);
}
}
sb.append('`');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.

import org.codehaus.groovy.runtime.IOGroovyMethods

suite ("test_mv_with_keyword") {

multi_sql """
drop table if exists t1_dup;
create table t1_dup (
`install` int,
```install``` int,
c1 int
)
duplicate key(`install`)
distributed BY hash(`install`) buckets 1
rollup (r1(```install```, `install`))
properties("replication_num" = "1");
insert into t1_dup values(1,1,1), (2,2,2);

drop table if exists t1_agg;
create table t1_agg (
`install` int,
```install``` int,
`kill` int sum
)
aggregate key(`install`, ```install```)
distributed BY hash(`install`) buckets 1
rollup (r1(```install```, `kill`))
properties("replication_num" = "1");
insert into t1_agg values(1,1,1), (2,2,2);
"""
createMV("create materialized view mv1 as select ```install``` as `select` from t1_dup where ```install``` > 0;")
createMV("create materialized view mv2 as select `install` as ```select``` from t1_dup where `install` > 0;")
createMV("create materialized view mv1 as select ```install``` as `select` from t1_agg group by ```install```;")
createMV("create materialized view mv2 as select `install` as ```select```, sum(`kill`) as ```kill``` from t1_agg group by `install`;")
explain {
sql("select ```install``` as `select` from t1_dup where ```install``` > 0;")
contains "(mv1)"
}
explain {
sql("select `install` as ```select``` from t1_dup where `install` > 0;")
contains "(mv2)"
}
explain {
sql("select ```install``` as `select` from t1_agg group by ```install```;")
contains "(mv1)"
}
explain {
sql("select `install` as ```select```, sum(`kill`) as ```kill``` from t1_agg group by `install`;")
contains "(mv2)"
}
}
Loading