Skip to content

Commit a462464

Browse files
guojn1githubgxll
authored andcommitted
[fix][dingo-calcite] Adjusted the return type of avg
1 parent 27d904e commit a462464

File tree

10 files changed

+27
-11
lines changed

10 files changed

+27
-11
lines changed

dingo-calcite/src/main/codegen/includes/AlterTable.ftl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ SqlAlterTable addIndex(Span s, String scope, SqlIdentifier id): {
293293
}
294294

295295
SqlAlterTable addUniqueIndex(Span s, String scope, SqlIdentifier id): {
296-
final String index;
296+
String index = null;
297+
SqlIdentifier tmpIndex = null;
297298
Boolean autoIncrement = false;
298299
Properties properties = null;
299300
PartitionDefinition partitionDefinition = null;
@@ -306,8 +307,13 @@ SqlAlterTable addUniqueIndex(Span s, String scope, SqlIdentifier id): {
306307
String indexAlg = null;
307308
String indexLockOpt = null;
308309
} {
309-
<UNIQUE> [<INDEX>][<KEY>] { s.add(this); }
310-
{ SqlIdentifier tmpIndex = SimpleIdentifier(); index = tmpIndex.getSimple(); }
310+
<UNIQUE> { s.add(this); }
311+
(
312+
<KEY>
313+
|
314+
<INDEX>
315+
)?
316+
( tmpIndex = SimpleIdentifier() { index = tmpIndex.getSimple(); } | { boolean hasName = false; })
311317
[<SCALAR>] columnList = indexColumns()
312318
(
313319
LOOKAHEAD(2)

dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2361,9 +2361,11 @@ private static IndexDefinition fromSqlUniqueDeclaration(
23612361
if (sqlKeyConstraint1.getReplica() >= 0) {
23622362
indexDefinition.setReplica(sqlKeyConstraint1.getReplica());
23632363
}
2364+
String engine = "TXN_LSM";
23642365
if (sqlKeyConstraint1.getEngine() != null) {
2365-
indexDefinition.setEngine(sqlKeyConstraint1.getEngine().toUpperCase());
2366+
engine = sqlKeyConstraint1.getEngine().toUpperCase();
23662367
}
2368+
indexDefinition.setEngine(engine);
23672369
indexDefinition.setPartDefinition(sqlKeyConstraint1.getPartDefinition());
23682370
validatePartitionBy(
23692371
indexDefinition.getKeyColumns().stream().map(ColumnDefinition::getName).collect(Collectors.toList()),

dingo-calcite/src/main/java/io/dingodb/calcite/executor/ShowCreateTableExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ private String getCreateTable() {
289289
if (!"TXN_LSM".equalsIgnoreCase(indexTable.getEngine())) {
290290
createTableSqlStr.append(" engine=").append(indexTable.getEngine());
291291
}
292+
if (StringUtils.isNotBlank(indexTable.getComment())) {
293+
createTableSqlStr.append(" comment ").append(indexTable.getComment());
294+
}
292295
appendPart(indexTable, createTableSqlStr);
293296
}
294297
}

dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/SqlIndexDeclaration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public SqlIndexDeclaration(
9090
.map(SqlIdentifier.class::cast)
9191
.map(SqlIdentifier::getSimple)
9292
.collect(Collectors.toCollection(ArrayList::new));
93+
if (this.index == null && !this.columnList.isEmpty()) {
94+
this.index = this.columnList.get(0);
95+
}
9396
}
9497
if (withColumnList != null) {
9598
this.withColumnList = withColumnList.getList().stream()

dingo-common/src/main/java/io/dingodb/common/ddl/DdlJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public String toString() {
353353
+ ", dependencyId=" + dependencyId
354354
+ ", query='" + query + '\''
355355
+ ", version=" + version
356-
+ ", args=" + args
356+
//+ ", args=" + args
357357
+ ", multiSchemaInfo=" + multiSchemaInfo
358358
+ ", priority=" + priority
359359
+ ", seqNu=" + seqNu

dingo-common/src/main/java/io/dingodb/common/util/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public static void checkAndUpdateTuples(DingoType schema, Object[] tuple) {
241241
Type[] dingoTypes = ((TupleType)schemaType).getTypes();
242242
for (int i = 0; i < dingoTypes.length; i++) {
243243
if (dingoTypes[i] instanceof io.dingodb.expr.common.type.DecimalType) {
244-
if (((io.dingodb.expr.common.type.DecimalType)dingoTypes[i]).getScale() == 0) {
244+
if (((io.dingodb.expr.common.type.DecimalType)dingoTypes[i]).getScale() == 0 && tuple[i] instanceof BigDecimal) {
245245
tuple[i] = ((BigDecimal)tuple[i]).setScale(0, RoundingMode.HALF_UP);
246246
}
247247
}

dingo-exec/src/main/java/io/dingodb/exec/fun/mysql/HexFun.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ protected Object evalNonNullValue(@NonNull Object value, ExprConfig config) {
4242
BigDecimal valueDecimal = (BigDecimal) value;
4343
return valueDecimal.toBigInteger().toString(16).toUpperCase();
4444
} else if (value instanceof Integer) {
45-
return Integer.toHexString((Integer) value).toUpperCase();
45+
Integer valInt = (Integer) value;
46+
return Long.toHexString(valInt.longValue()).toUpperCase();
4647
} else if (value instanceof Long) {
4748
return Long.toHexString((Long) value).toUpperCase();
4849
} else {

dingo-exec/src/main/java/io/dingodb/exec/operator/TxnPartInsertOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ protected boolean pushTuple(Context context, Object[] tuple, Vertex vertex) {
123123
throw new DingoTypeRangeException(0, "Out of range value for column '" + originColumns.get(i).getName() + "'");
124124
}
125125
}
126-
} else if(originColumns.get(i).getSqlTypeName().equalsIgnoreCase("TINYINT")) {
127-
if(tuple[i] instanceof Integer) {
126+
} else if (originColumns.get(i).getSqlTypeName().equalsIgnoreCase("TINYINT")) {
127+
if (tuple[i] instanceof Integer) {
128128
if (!Utils.tinyintInRange((Integer)tuple[i])) {
129129
throw new DingoTypeRangeException(0, "Out of range value for column '" + originColumns.get(i).getName() + "'");
130130
}

dingo-executor/src/main/java/io/dingodb/server/executor/ddl/DdlWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ public Pair<Long, String> onCreateTableAsQuery(DdlContext dc, DdlJob job) {
26452645
job.setActionType(originType);
26462646
job.setDingoErr(DingoErrUtil.newInternalErr(e.getMessage()));
26472647
DdlContext.INSTANCE.getSchemaSyncer().ownerUpdateExpVersion(res.getKey());
2648+
job.setState(JobState.jobStateCancelled);
26482649
return Pair.of(0L, job.getDingoErr().errorMsg);
26492650
}
26502651
}

dingo-test/src/test/java/io/dingodb/test/dsl/BasicQueryCases.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,8 @@ public void build() {
822822
.step(
823823
"select avg(age) aag,avg(gmt) agm,avg(price) apr,round(avg(amount),2) aam from {table}",
824824
csv("aag, agm, apr, aam",
825-
"DECIMAL, DECIMAL, FLOAT, DOUBLE",
826-
"107.6000, -17057004875.5000, 9.341029E8, 1.305008494926E10")
825+
"DECIMAL, DECIMAL, DOUBLE, DOUBLE",
826+
"107.6000, -17057004875.5000, 9.341029376E8, 1.305008494926E10")
827827
);
828828
}
829829
}

0 commit comments

Comments
 (0)