re
if (table instanceof SqlIdentifier || table instanceof SqlDynamicParam) {
// Table
this.columnCount = refTables.get(0).getRowType().getFieldCount();
+ } else if (RelOptUtil.isUnion(table)) {
+ this.columnCount = RelOptUtil.getColumnCount(table);
} else {
// Subquery
SqlSelect subquery = (SqlSelect) table;
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/TableScan.java b/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/TableScan.java
index 73816e44a..8b65158b3 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/TableScan.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/TableScan.java
@@ -35,6 +35,7 @@
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.util.ImmutableBitSet;
@@ -78,6 +79,11 @@ public abstract class TableScan extends AbstractRelNode {
*/
protected RexNode flashback;
+ /**
+ * 记录AS OF 种类:AS_OF/AS_OF_80/AS_OF_57
+ */
+ protected SqlOperator flashbackOperator;
+
/**
* This tableName identifier's partitions of mysql partition selection syntax
*
@@ -108,11 +114,11 @@ protected TableScan(RelOptCluster cluster, RelTraitSet traitSet,
protected TableScan(RelOptCluster cluster, RelTraitSet traitSet,
RelOptTable table, SqlNodeList hints, SqlNode indexNode) {
- this(cluster, traitSet, table, hints, indexNode, null, null);
+ this(cluster, traitSet, table, hints, indexNode, null, null, null);
}
protected TableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, SqlNodeList hints,
- SqlNode indexNode, RexNode flashback, SqlNode partitions) {
+ SqlNode indexNode, RexNode flashback, SqlOperator flashbackOperator, SqlNode partitions) {
super(cluster, traitSet);
this.table = table;
this.hints = hints;
@@ -121,6 +127,7 @@ protected TableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable tab
cluster.getPlanner().registerSchema(table.getRelOptSchema());
}
this.flashback = flashback;
+ this.flashbackOperator = flashbackOperator;
this.partitions = partitions;
}
/**
@@ -265,6 +272,14 @@ public void setFlashback(RexNode flashback) {
this.flashback = flashback;
}
+ public SqlOperator getFlashbackOperator() {
+ return flashbackOperator;
+ }
+
+ public void setFlashbackOperator(SqlOperator flashbackOperator) {
+ this.flashbackOperator = flashbackOperator;
+ }
+
public SqlNode getPartitions() {
return partitions;
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/WindowAggregateCall.java b/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/WindowAggregateCall.java
index 2f056fc9d..78456a56b 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/WindowAggregateCall.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/rel/core/WindowAggregateCall.java
@@ -67,6 +67,25 @@ public WindowAggregateCall copy(List args, int filterArg, List args, int filterArg) {
+ return new WindowAggregateCall(aggFunction, distinct, approximate, args,
+ filterArg, type, name, constants, offset);
+ }
+
+ @Override
+ public AggregateCall copy(List args, int filterArg, boolean isDistinct, String newName) {
+ return new WindowAggregateCall(aggFunction, isDistinct, approximate, args,
+ filterArg, type, newName, constants, offset);
+ }
+
+ @Override
+ public AggregateCall withDistinct(boolean distinct) {
+ return distinct == this.distinct ? this
+ : new WindowAggregateCall(aggFunction, distinct, approximate, argList, filterArg, type, name,
+ constants, offset);
+ }
+
public AggregateCall create(SqlAggFunction aggFunction,
boolean distinct, boolean approximate, List argList,
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/rel/logical/LogicalTableScan.java b/polardbx-calcite/src/main/java/org/apache/calcite/rel/logical/LogicalTableScan.java
index 763733402..52eed454c 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/rel/logical/LogicalTableScan.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/rel/logical/LogicalTableScan.java
@@ -31,6 +31,7 @@
import org.apache.calcite.schema.Table;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.parser.SqlParserPos;
import java.util.List;
@@ -81,8 +82,9 @@ public LogicalTableScan(RelOptCluster cluster, RelTraitSet traitSet,
public LogicalTableScan(RelOptCluster cluster, RelTraitSet traitSet,
RelOptTable table, SqlNodeList hints, SqlNode indexNode, RexNode flashback,
+ SqlOperator flashbackOperator,
SqlNode partitions) {
- super(cluster, traitSet, table, hints, indexNode, flashback, partitions);
+ super(cluster, traitSet, table, hints, indexNode, flashback, flashbackOperator, partitions);
}
@Deprecated // to be removed before 2.0
@@ -110,12 +112,12 @@ public LogicalTableScan(RelInput input) {
*/
public static LogicalTableScan create(RelOptCluster cluster,
final RelOptTable relOptTable) {
- return create(cluster, relOptTable, new SqlNodeList(SqlParserPos.ZERO), null, null, null);
+ return create(cluster, relOptTable, new SqlNodeList(SqlParserPos.ZERO), null, null, null, null);
}
public static LogicalTableScan create(RelOptCluster cluster,
final RelOptTable relOptTable, SqlNodeList hints, SqlNode indexNode,
- RexNode flashback, SqlNode partitions) {
+ RexNode flashback, SqlOperator flashbackOperator, SqlNode partitions) {
final Table table = relOptTable.unwrap(Table.class);
final RelTraitSet traitSet =
@@ -127,7 +129,8 @@ public static LogicalTableScan create(RelOptCluster cluster,
}
return ImmutableList.of();
}).simplify();
- return new LogicalTableScan(cluster, traitSet, relOptTable, hints, indexNode, flashback, partitions);
+ return new LogicalTableScan(cluster, traitSet, relOptTable, hints, indexNode, flashback, flashbackOperator,
+ partitions);
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/polardbx-calcite/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 076e55f15..b46e8b9f9 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -1441,7 +1441,8 @@ public SqlNode asFrom() {
final SqlIdentifier identifier = (SqlIdentifier) node;
final SqlIdentifier newIdentifier =
new SqlIdentifier(((SqlIdentifier) node).names, ((SqlIdentifier) node).getCollation(),
- node.getParserPosition(), null, null, identifier.partitions, identifier.flashback);
+ node.getParserPosition(), null, null, identifier.partitions, identifier.flashback,
+ identifier.flashbackOperator);
final SqlIdentifier alias =
new SqlIdentifier(ImmutableList.of(neededAlias), null, POS, null, identifier.indexNode);
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAggFunction.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
index 6c1f6481a..c78b4372c 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAggFunction.java
@@ -24,7 +24,9 @@
import org.apache.calcite.sql.type.SqlReturnTypeInference;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorScope;
+import org.apache.calcite.util.Optionality;
+import javax.annotation.Nonnull;
import java.util.List;
/**
@@ -131,6 +133,23 @@ public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
public boolean allowsFilter() {
return true;
}
+
+ /** Returns whether this aggregate function allows the {@code DISTINCT}
+ * keyword.
+ *
+ * The default implementation returns {@link Optionality#OPTIONAL},
+ * which is appropriate for most aggregate functions, including {@code SUM}
+ * and {@code COUNT}.
+ *
+ *
Some aggregate functions, for example {@code MIN}, produce the same
+ * result with or without {@code DISTINCT}, and therefore return
+ * {@link Optionality#IGNORED} to indicate this. For such functions,
+ * Calcite will probably remove {@code DISTINCT} while optimizing the query.
+ */
+ public @Nonnull
+ Optionality getDistinctOptionality() {
+ return Optionality.OPTIONAL;
+ }
}
// End SqlAggFunction.java
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAsOf57Operator.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAsOf57Operator.java
new file mode 100644
index 000000000..0f2737765
--- /dev/null
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlAsOf57Operator.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright [2013-2021], Alibaba Group Holding Limited
+ *
+ * Licensed 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.
+ */
+
+package org.apache.calcite.sql;
+
+import org.apache.calcite.sql.type.InferTypes;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.sql.type.SqlOperandTypeChecker;
+import org.apache.calcite.sql.type.SqlOperandTypeInference;
+import org.apache.calcite.sql.type.SqlReturnTypeInference;
+
+public class SqlAsOf57Operator extends SqlSpecialOperator {
+ public SqlAsOf57Operator() {
+ this(
+ "AS OF TSO",
+ SqlKind.AS_OF,
+ 20,
+ true,
+ ReturnTypes.ARG0,
+ InferTypes.RETURN_TYPE,
+ OperandTypes.ANY_ANY);
+ }
+
+ protected SqlAsOf57Operator(String name, SqlKind kind, int prec,
+ boolean leftAssoc, SqlReturnTypeInference returnTypeInference,
+ SqlOperandTypeInference operandTypeInference,
+ SqlOperandTypeChecker operandTypeChecker) {
+ super(name, kind, prec, leftAssoc, returnTypeInference,
+ operandTypeInference, operandTypeChecker);
+ }
+
+ public void unparse(
+ SqlWriter writer,
+ SqlCall call,
+ int leftPrec,
+ int rightPrec) {
+ assert call.operandCount() >= 2;
+ final SqlWriter.Frame frame =
+ writer.startList(
+ SqlWriter.FrameTypeEnum.SIMPLE);
+ call.operand(0).unparse(writer, leftPrec, getLeftPrec());
+ final boolean needsSpace = true;
+ writer.setNeedWhitespace(needsSpace);
+ if (writer.getDialect().allowsAsOf()) {
+ writer.sep("AS OF TSO");
+ writer.setNeedWhitespace(needsSpace);
+ }
+ call.operand(1).unparse(writer, getRightPrec(), rightPrec);
+ writer.endList(frame);
+ }
+}
\ No newline at end of file
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlCreateTable.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlCreateTable.java
index 03efd077c..ca20cf251 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlCreateTable.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlCreateTable.java
@@ -521,6 +521,8 @@ public boolean shouldLoad() {
|| trimmedComment.equalsIgnoreCase("load_s3")
|| trimmedComment.equalsIgnoreCase("load_local_disk")
|| trimmedComment.equalsIgnoreCase("load_nfs")
+ || trimmedComment.equalsIgnoreCase("load_s3")
+ || trimmedComment.equalsIgnoreCase("load_abs")
|| trimmedComment.equalsIgnoreCase("load_external_disk");
}
@@ -2738,8 +2740,7 @@ public static void addCompositeIndex(Map indexColumn
Set orderedIndexColumnNames = new LinkedHashSet<>(shardingKey);
final String suffix = buildUnifyIndexName(orderedIndexColumnNames, 45);
- final String indexName = addFkIndex ? (foreignKeyIndexName == null ?
- buildForeignKeyIndexName(existingIndexNames, suffix) : foreignKeyIndexName) :
+ final String indexName = addFkIndex ? buildForeignKeyName(foreignKeyIndexName, existingIndexNames, suffix) :
buildIndexName(existingIndexNames, suffix);
final MySqlTableIndex mySqlTableIndex = new MySqlTableIndex();
@@ -2765,6 +2766,13 @@ public static void addCompositeIndex(Map indexColumn
}
}
+ public static String buildForeignKeyName(String foreignKeyIndexName, Set existingIndexNames,
+ String suffix) {
+ return foreignKeyIndexName == null ?
+ buildForeignKeyIndexName(existingIndexNames, suffix) :
+ SqlIdentifier.surroundWithBacktick(foreignKeyIndexName);
+ }
+
private static List preparAutoCompositeIndexs(List shardKeys,
Map columnDefMap,
int maxLen) {
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlIdentifier.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
index 0d3773357..79666c431 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
@@ -100,6 +100,11 @@ public String apply(String s) {
*/
public SqlNode flashback;
+ /**
+ * 记录AS OF 种类:AS_OF/AS_OF_80/AS_OF_57
+ */
+ public SqlOperator flashbackOperator;
+
/**
* This identifier's collation (if any).
*/
@@ -153,7 +158,7 @@ public SqlIdentifier(
// for (String name : names) {
// assert name != null;
// }
- this(names, collation, pos, componentPositions, null, null, null);
+ this(names, collation, pos, componentPositions, null, null, null, null);
}
public SqlIdentifier(
@@ -161,14 +166,14 @@ public SqlIdentifier(
SqlCollation collation,
SqlParserPos pos,
List componentPositions, SqlNode indexNode) {
- this(names, collation, pos, componentPositions, indexNode, null, null);
+ this(names, collation, pos, componentPositions, indexNode, null, null, null);
}
public SqlIdentifier(
String name,
SqlParserPos pos,
SqlNode indexNode) {
- this(ImmutableList.of(name), null, pos, null, indexNode, null, null);
+ this(ImmutableList.of(name), null, pos, null, indexNode, null, null, null);
}
/**
@@ -181,6 +186,15 @@ public SqlIdentifier(
SqlCollation collation,
SqlParserPos pos,
List componentPositions, SqlNode indexNode, SqlNode partitions, SqlNode flashback) {
+ this(ImmutableList.copyOf(names), collation, pos, componentPositions, indexNode, partitions, flashback, null);
+ }
+
+ public SqlIdentifier(
+ List names,
+ SqlCollation collation,
+ SqlParserPos pos,
+ List componentPositions, SqlNode indexNode, SqlNode partitions, SqlNode flashback,
+ SqlOperator flashbackOperator) {
super(pos);
this.names = ImmutableList.copyOf(names);
this.collation = collation;
@@ -192,16 +206,21 @@ public SqlIdentifier(
this.indexNode = indexNode;
this.partitions = partitions;
this.flashback = flashback;
+ this.flashbackOperator = flashbackOperator;
}
- /** Creates an identifier that is a singleton wildcard star. */
+ /**
+ * Creates an identifier that is a singleton wildcard star.
+ */
public static SqlIdentifier star(SqlParserPos pos) {
return star(ImmutableList.of(""), pos, ImmutableList.of(pos));
}
- /** Creates an identifier that ends in a wildcard star. */
+ /**
+ * Creates an identifier that ends in a wildcard star.
+ */
public static SqlIdentifier star(List names, SqlParserPos pos,
- List componentPositions) {
+ List componentPositions) {
return new SqlIdentifier(Lists.transform(names, STAR_TO_EMPTY), null, pos,
componentPositions);
}
@@ -213,7 +232,7 @@ public SqlKind getKind() {
}
@Override public SqlNode clone(SqlParserPos pos) {
- return new SqlIdentifier(names, collation, pos, componentPositions, indexNode, partitions, flashback);
+ return new SqlIdentifier(names, collation, pos, componentPositions, indexNode, partitions, flashback, flashbackOperator);
}
public String toStringWithBacktick() {
@@ -498,6 +517,10 @@ public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
final SqlIdentifier fqId = qualified.identifier;
return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names));
}
+
+ public SqlOperator getFlashbackOperator() {
+ return flashbackOperator;
+ }
}
// End SqlIdentifier.java
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlMoveDatabase.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlMoveDatabase.java
index 2309d33f7..03a8844fa 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlMoveDatabase.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlMoveDatabase.java
@@ -57,7 +57,7 @@ public SqlMoveDatabase(SqlParserPos pos, Map> storageGroups
this.isCleanUpCommand = isCleanUpCommand;
if (!isCleanUpCommand) {
this.currentSourceGroupKey = firstGroup;
- this.currentTargetGroupKey = GroupInfoUtil.buildScaloutGroupName(firstGroup);
+ this.currentTargetGroupKey = GroupInfoUtil.buildScaleOutGroupName(firstGroup);
}
}
@@ -75,7 +75,7 @@ public void setCurrentStorageInstId(String currentStorageInstId) {
public void setCleanUpGroups(String groupName) {
Map> toBeCleanGroups = new HashMap<>();
- toBeCleanGroups.put(VIRTUAL_STORAGE_ID, ImmutableList.of(GroupInfoUtil.buildScaloutGroupName(groupName)));
+ toBeCleanGroups.put(VIRTUAL_STORAGE_ID, ImmutableList.of(GroupInfoUtil.buildScaleOutGroupName(groupName)));
this.storageGroups = toBeCleanGroups;
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlPartition.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlPartition.java
index aecea5263..78e2d5604 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlPartition.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlPartition.java
@@ -16,16 +16,9 @@
package org.apache.calcite.sql;
-import com.alibaba.polardbx.common.exception.TddlRuntimeException;
-import com.alibaba.polardbx.common.exception.code.ErrorCode;
-import com.alibaba.polardbx.common.utils.GeneralUtil;
import com.alibaba.polardbx.common.utils.TStringUtil;
import com.alibaba.polardbx.druid.util.StringUtils;
-import com.google.common.base.Preconditions;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.util.SqlVisitor;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorScope;
@@ -76,18 +69,37 @@ public String toString() {
StringBuilder sb = new StringBuilder("");
sb.append("PARTITION ");
sb.append(name);
- sb.append(" ");
- sb.append(values.toString());
+ if (values != null) {
+ sb.append(" ");
+ sb.append(values.toString());
+ }
if (TStringUtil.isNotEmpty(locality)) {
sb.append(" LOCALITY=");
sb.append(TStringUtil.quoteString(locality));
}
+
+ if (subPartitionCount != null) {
+ sb.append(" ");
+ sb.append("SUBPARTITIONS ");
+ sb.append(subPartitionCount.toString());
+ }
+ if (subPartitions != null && !subPartitions.isEmpty()) {
+ sb.append(" ");
+ sb.append("(");
+ for (int i = 0; i < subPartitions.size(); i++) {
+ if (i > 0) {
+ sb.append(",");
+ }
+ SqlNode subPart = subPartitions.get(i);
+ sb.append(subPart.toString());
+ }
+ sb.append(")");
+ }
return sb.toString();
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
-
}
@Override
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlSubPartition.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlSubPartition.java
index 1adebaab7..9953a844d 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlSubPartition.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlSubPartition.java
@@ -70,8 +70,10 @@ public String toString() {
StringBuilder sb = new StringBuilder("");
sb.append("SUBPARTITION ");
sb.append(name);
- sb.append(" ");
- sb.append(values.toString());
+ if (values != null) {
+ sb.append(" ");
+ sb.append(values.toString());
+ }
if (TStringUtil.isNotEmpty(locality)) {
sb.append(" LOCALITY=");
sb.append(TStringUtil.quoteString(locality));
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlTableOptions.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlTableOptions.java
index cf07383d3..c25005ba2 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlTableOptions.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/SqlTableOptions.java
@@ -50,7 +50,7 @@ public class SqlTableOptions extends SqlCall {
private SqlCharStringLiteral indexDir;
private SqlLiteral delayKeyWrite;
private InsertMethod insertMethod;
- private SqlCall keyBlockSize;
+ private SqlNumericLiteral keyBlockSize;
private SqlNumericLiteral maxRows;
private SqlNumericLiteral minRows;
private PackKeys packKeys;
@@ -304,11 +304,11 @@ public void setInsertMethod(InsertMethod insertMethod) {
this.insertMethod = insertMethod;
}
- public SqlCall getKeyBlockSize() {
+ public SqlNumericLiteral getKeyBlockSize() {
return keyBlockSize;
}
- public void setKeyBlockSize(SqlCall keyBlockSize) {
+ public void setKeyBlockSize(SqlNumericLiteral keyBlockSize) {
this.keyBlockSize = keyBlockSize;
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
index 94f855bec..78010e75d 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
@@ -16,6 +16,8 @@
*/
package org.apache.calcite.sql.fun;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.sql.SqlAggFunction;
@@ -24,10 +26,8 @@
import org.apache.calcite.sql.SqlSplittableAggFunction;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
import org.apache.calcite.sql.type.SqlReturnTypeInference;
+import org.apache.calcite.util.Optionality;
import java.util.List;
@@ -142,6 +142,10 @@ public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
}
return super.unwrap(clazz);
}
+
+ @Override public Optionality getDistinctOptionality() {
+ return Optionality.IGNORED;
+ }
}
// End SqlMinMaxAggFunction.java
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
index 6e745df1a..258cd3783 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
@@ -16,6 +16,7 @@
*/
package org.apache.calcite.sql.fun;
+import com.google.common.collect.ImmutableList;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.sql.SqlAggFunction;
@@ -23,8 +24,7 @@
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
-
-import com.google.common.collect.ImmutableList;
+import org.apache.calcite.util.Optionality;
import java.util.List;
@@ -71,6 +71,10 @@ public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
public RelDataType getType() {
return type;
}
+
+ @Override public Optionality getDistinctOptionality() {
+ return Optionality.IGNORED;
+ }
}
// End SqlSingleValueAggFunction.java
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
index aab31c07a..bd9d15224 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
@@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableList;
import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlAsOf57Operator;
import org.apache.calcite.sql.SqlAsOf80Operator;
import org.apache.calcite.sql.SqlAsOfOperator;
import org.apache.calcite.sql.SqlAsOperator;
@@ -173,9 +174,20 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
* with an alias.
*/
public static final SqlAsOperator AS = new SqlAsOperator();
+ /**
+ * as of timestamp; 5.7 物理sql使用 as of timestamp; 8.0 需转成 AS OF GCN
+ */
public static final SqlAsOfOperator AS_OF = new SqlAsOfOperator();
+ /**
+ * 8.0版本: 用户sql为as of tso,物理sql使用 AS OF GCN
+ */
public static final SqlAsOf80Operator AS_OF_80 = new SqlAsOf80Operator();
+ /**
+ * 5.7 版本: 用户sql为as of tso,物理sql使用 as of tso
+ */
+ public static final SqlAsOf57Operator AS_OF_57 = new SqlAsOf57Operator();
+
/**
* ARGUMENT_ASSIGNMENT
operator (=<
)
* assigns an argument to a function call to a particular named parameter.
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
index 3d75d4e9e..8271c5fbf 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
@@ -73,8 +73,6 @@ public enum SqlTypeName {
REAL(PrecScale.NO_NO, false, Types.REAL, SqlTypeFamily.NUMERIC),
DOUBLE(PrecScale.NO_NO, false, Types.DOUBLE, SqlTypeFamily.NUMERIC),
- // TODO: remove UNSIGNED/SIGNED
- // add by xiaoying
UNSIGNED(PrecScale.NO_NO, false, Types.BIGINT, SqlTypeFamily.NUMERIC),
SIGNED(PrecScale.NO_NO, false, Types.BIGINT, SqlTypeFamily.NUMERIC),
@@ -170,7 +168,16 @@ public enum SqlTypeName {
public static final int MAX_TIME_FRACTIONAL_SECOND_SCALE = 6;
// Cached map of enum values
- private static final Map VALUES_MAP = Util.enumConstants(SqlTypeName.class);
+ private static final Map VALUES_MAP = ImmutableMap.builder()
+ .putAll(Util.enumConstants(SqlTypeName.class))
+ // For Alias in MySQL https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast
+ // SIGNED [INTEGER]
+ // Produces a signed BIGINT value.
+ // UNSIGNED [INTEGER]
+ // Produces an unsigned BIGINT value.
+ .put("SIGNED INTEGER", SIGNED)
+ .put("UNSIGNED INTEGER", UNSIGNED)
+ .build();
// categorizations used by SqlTypeFamily definitions
@@ -397,15 +404,6 @@ public static long getSize() {
* @return Type name, or null if not found
*/
public static SqlTypeName get(String name) {
- if (false) {
- // The following code works OK, but the spurious exceptions are
- // annoying.
- try {
- return SqlTypeName.valueOf(name);
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
return VALUES_MAP.get(name);
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 75c80c82b..bc3fcc42f 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -5606,7 +5606,17 @@ public void validateGsiColumn(List> glob
}
}
- public static void validateUnsupportedColumTypeWithCci(MySqlCreateTableStatement stmt, List primaryKeys,
+ public static void validateUnsupportedTypeWithCciWhenModifyColumn(SqlColumnDeclaration columnDeclaration) {
+ final List deniedTypes = Arrays.asList(
+ "text", "binary", "varbinary", "blob", "timestamp", "time", "year", "json", "enum", "set", "point", "geometry");
+ String columnType = columnDeclaration.getDataType().getTypeName().getLastName().toLowerCase();
+ if (deniedTypes.contains(columnType)) {
+ throw new TddlRuntimeException(ErrorCode.ERR_UNSUPPORTED_COLUMN_TYPE_WITH_CCI,
+ "MODIFY/CHANGE COLUMN", columnType);
+ }
+ }
+
+ public static void validateUnsupportedColumnTypeWithCci(MySqlCreateTableStatement stmt, List primaryKeys,
List sortKeys, List shardingKeys) {
final String[] deniedTypes = {
"float", "double", "decimal", "numeric", "json", "enum", "set", "point", "geometry"};
@@ -6900,6 +6910,10 @@ public void validateInsert(SqlInsert insert) {
insert.getTargetColumnList(),
false, null);
+ // for INSERT t() values(), in which no source or target column list is specified,
+ // rewrite SqlNode with INSERT t() values(DEFAULT, DEFAULT, ...)
+ checkAndRewriteEmptySource(insert, targetRowType);
+
final SqlNode source = insert.getSource();
if (source instanceof SqlSelect) {
final SqlSelect sqlSelect = (SqlSelect) source;
@@ -6948,6 +6962,29 @@ public void validateInsert(SqlInsert insert) {
}
}
+ public void checkAndRewriteEmptySource(SqlInsert insert, RelDataType targetRowType) {
+ if (insert.getTargetColumnList() == null) {
+ final SqlNode originSource = insert.getSource();
+ if (originSource instanceof SqlBasicCall && originSource.getKind() == SqlKind.VALUES) {
+ final SqlBasicCall values = (SqlBasicCall) originSource;
+ final SqlBasicCall row = (SqlBasicCall) values.getOperands()[0];
+ // If target column list and source value list is all empty,
+ // rewrite source to VALUES(DEFAULT, DEFAULT, ...)
+ if (row.getOperands() == null || row.getOperands().length == 0) {
+ final List fieldNames = targetRowType.getFieldNames();
+ final long fieldCount = fieldNames.stream().filter(f -> !isImplicitKey(f)).count();
+ final SqlNode[] defaults = new SqlNode[(int) fieldCount];
+ for (int i = 0; i < defaults.length; i++) {
+ // Add DEFAULT to VALUES for each target column
+ defaults[i] =
+ new SqlBasicCall(SqlStdOperatorTable.DEFAULT, SqlNode.EMPTY_ARRAY, SqlParserPos.ZERO);
+ }
+ values.setOperand(0, new SqlBasicCall(row.getOperator(), defaults, row.getParserPosition()));
+ }
+ }
+ }
+ }
+
/**
* Validates insert values against the constraint of a modifiable view.
*
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/polardbx-calcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index cbca1b158..a4f7a5e07 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -108,8 +108,8 @@
import org.apache.calcite.rel.ddl.AlterTableSetTableGroup;
import org.apache.calcite.rel.ddl.AnalyzeTable;
import org.apache.calcite.rel.ddl.ChangeConsensusRole;
-import org.apache.calcite.rel.ddl.ConvertAllSequences;
import org.apache.calcite.rel.ddl.ClearFileStorage;
+import org.apache.calcite.rel.ddl.ConvertAllSequences;
import org.apache.calcite.rel.ddl.CreateDatabase;
import org.apache.calcite.rel.ddl.CreateFileStorage;
import org.apache.calcite.rel.ddl.CreateFunction;
@@ -178,6 +178,7 @@
import org.apache.calcite.rel.logical.LogicalUnion;
import org.apache.calcite.rel.logical.LogicalValues;
import org.apache.calcite.rel.metadata.RelColumnMapping;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.stream.Delta;
import org.apache.calcite.rel.stream.LogicalDelta;
import org.apache.calcite.rel.type.RelDataType;
@@ -260,8 +261,8 @@
import org.apache.calcite.sql.SqlChangeConsensusRole;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlCheckColumnarIndex;
-import org.apache.calcite.sql.SqlConvertAllSequences;
import org.apache.calcite.sql.SqlClearFileStorage;
+import org.apache.calcite.sql.SqlConvertAllSequences;
import org.apache.calcite.sql.SqlCreate;
import org.apache.calcite.sql.SqlCreateDatabase;
import org.apache.calcite.sql.SqlCreateFileStorage;
@@ -347,8 +348,8 @@
import org.apache.calcite.sql.SqlUpdate;
import org.apache.calcite.sql.SqlUtil;
import org.apache.calcite.sql.SqlUtil.SpecialIdentiFiers;
-import org.apache.calcite.sql.SqlValuesTableSource;
import org.apache.calcite.sql.SqlValuesOperator;
+import org.apache.calcite.sql.SqlValuesTableSource;
import org.apache.calcite.sql.SqlWindow;
import org.apache.calcite.sql.SqlWith;
import org.apache.calcite.sql.SqlWithItem;
@@ -513,7 +514,7 @@ public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator val
Prepare.CatalogReader catalogReader, RelOptPlanner planner, RexBuilder rexBuilder,
SqlRexConvertletTable convertletTable) {
this(viewExpander, validator, catalogReader, RelOptCluster.create(planner, rexBuilder), convertletTable,
- Config.DEFAULT, Integer.MAX_VALUE);
+ Config.DEFAULT, Integer.MAX_VALUE, false);
}
@Deprecated // to be removed before 2.0
@@ -526,13 +527,15 @@ public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator val
public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator validator,
Prepare.CatalogReader catalogReader, RelOptCluster cluster,
SqlRexConvertletTable convertletTable, Config config) {
- this(viewExpander, validator, catalogReader, cluster, convertletTable, config, config.getInSubQueryThreshold());
+ this(viewExpander, validator, catalogReader, cluster, convertletTable, config, config.getInSubQueryThreshold(),
+ config.isRemoveDistinct());
}
/* Creates a converter. */
public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator validator,
Prepare.CatalogReader catalogReader, RelOptCluster cluster,
- SqlRexConvertletTable convertletTable, Config config, int inSubQueryThreshold) {
+ SqlRexConvertletTable convertletTable, Config config, int inSubQueryThreshold,
+ boolean isRemoveDistinct) {
this.viewExpander = viewExpander;
this.opTab = (validator == null) ? SqlStdOperatorTable.instance() : validator.getOperatorTable();
this.validator = validator;
@@ -543,7 +546,9 @@ public SqlToRelConverter(RelOptTable.ViewExpander viewExpander, SqlValidator val
this.cluster = Preconditions.checkNotNull(cluster);
this.exprConverter = new SqlNodeToRexConverterImpl(convertletTable);
this.explainParamCount = 0;
- this.config = new ConfigBuilder().withConfig(config).withInSubQueryThreshold(inSubQueryThreshold).build();
+ this.config = new ConfigBuilder().withConfig(config)
+ .withInSubQueryThreshold(inSubQueryThreshold)
+ .withRemoveDistinct(isRemoveDistinct).build();
this.relBuilder = RelFactories.LOGICAL_BUILDER.create(cluster, null);
}
@@ -2170,7 +2175,7 @@ protected void convertFrom(Blackboard bb, SqlNode from) {
SqlNode tableName = call.operand(0);
SqlNode timeStamp = call.operand(1);
final RexNode timestampExpr = bb.convertExpression(timeStamp);
- this.hintBlackboard.beginAsOf(timestampExpr);
+ this.hintBlackboard.beginAsOf(Pair.of(timestampExpr, call.getOperator()));
SqlIdentifier identifier = (SqlIdentifier) tableName;
convertIdentifier(bb, identifier, null, identifier.indexNode, identifier.partitions);
this.hintBlackboard.endAsOf();
@@ -2606,10 +2611,11 @@ private void convertIdentifier(Blackboard bb, SqlIdentifier id, SqlNodeList exte
} else {
SqlNodeList hint = this.hintBlackboard.currentHints(Util.last(table.getQualifiedName()));
if (this.hintBlackboard.hasAsOf()) {
- tableRel = LogicalTableScan.create(cluster, table, hint, indexNode, this.hintBlackboard.peekAsOf(),
+ Pair asOf = this.hintBlackboard.peekAsOf();
+ tableRel = LogicalTableScan.create(cluster, table, hint, indexNode, asOf.getKey(), asOf.getValue(),
partitions);
} else {
- tableRel = LogicalTableScan.create(cluster, table, hint, indexNode, null, partitions);
+ tableRel = LogicalTableScan.create(cluster, table, hint, indexNode, null, null, partitions);
}
}
@@ -3305,7 +3311,61 @@ protected final void createAggImpl(Blackboard bb, final AggConverter aggConverte
*/
protected RelNode createAggregate(Blackboard bb, ImmutableBitSet groupSet, ImmutableList groupSets,
List aggCalls) {
- return LogicalAggregate.create(bb.root, groupSet, groupSets, aggCalls);
+
+ final List aggregateCalls = new ArrayList<>();
+ Set nullRefs = new HashSet<>();
+ for (AggregateCall aggregateCall : aggCalls) {
+ if (groupSets.size() <= 1 && config.isRemoveDistinct()) {
+ aggregateCall = removeRedundantAggregateDistinct(
+ aggregateCall, groupSet, bb.root, nullRefs);
+ }
+ aggregateCalls.add(aggregateCall);
+ }
+
+ RelNode relNode = bb.root;
+ if (nullRefs.size() > 0) {
+ final List fields = relNode.getRowType().getFieldList();
+ final List isNotNullOperands = new ArrayList<>();
+ for (Integer nullRef : nullRefs) {
+ RelDataType dataType = fields.get(nullRef).getType();
+ if (dataType.isNullable()) {
+ isNotNullOperands.add(relBuilder.isNotNull(rexBuilder.makeInputRef(relNode, nullRef)));
+ }
+ }
+ if (isNotNullOperands.size() > 0) {
+ relNode = LogicalFilter.create(
+ relNode, RexUtil.composeConjunction(rexBuilder, isNotNullOperands, true));
+ }
+ }
+ return LogicalAggregate.create(relNode, groupSet, groupSets, aggregateCalls);
+ }
+
+ private AggregateCall removeRedundantAggregateDistinct(
+ AggregateCall aggregateCall,
+ ImmutableBitSet groupSet,
+ RelNode relNode,
+ Set nullRefs) {
+ final List argList = aggregateCall.getArgList();
+ if (aggregateCall.isDistinct()) {
+ final RelMetadataQuery mq = relNode.getCluster().getMetadataQuery();
+ final ImmutableBitSet distinctArg = ImmutableBitSet.builder()
+ .addAll(argList)
+ .build();
+ final ImmutableBitSet columns = groupSet.union(distinctArg);
+ final Boolean alreadyUnique =
+ mq.areColumnsUnique(relNode, columns);
+ if (alreadyUnique != null && alreadyUnique) {
+ // columns have been distinct or columns are primary keys
+ if (aggregateCall.getAggregation().getKind() == SqlKind.COUNT) {
+ //in order to avoid generate the physical sql "count(a, b, c)" for the singleTable,
+ //and mysql don't support count multi-column.
+ return aggregateCall;
+ } else {
+ return aggregateCall.withDistinct(false);
+ }
+ }
+ }
+ return aggregateCall;
}
public RexDynamicParam convertDynamicParam(final SqlDynamicParam dynamicParam) {
@@ -5063,7 +5123,7 @@ protected List getUpdateSrcTables(SqlUpdate sqlUpdate) {
if (srcNode instanceof SqlIdentifier) {
// Table name
result.add(new TableInfoNode(srcNode, srcWithAlias, ImmutableList.of(getTargetTable(srcNode))));
- } else if (srcNode instanceof SqlSelect) {
+ } else if (srcNode instanceof SqlSelect || RelOptUtil.isUnion(srcNode)) {
// SubQuery
final List tableNames = sqlUpdate.subQueryTables(srcNode);
result.add(new TableInfoNode(srcNode, srcWithAlias,
@@ -5110,7 +5170,7 @@ protected TableInfo getDeleteTargetTables(SqlDelete sqlDelete, Blackboard bb, Re
// Table name
srcTableInfos.add(
new TableModify.TableInfoNode(srcNode, srcWithAlias, ImmutableList.of(getTargetTable(srcNode))));
- } else if (srcNode instanceof SqlSelect) {
+ } else if (srcNode instanceof SqlSelect || RelOptUtil.isUnion(srcNode)) {
// SubQuery
final List tableNames = sqlDelete.subQueryTables(srcNode);
srcTableInfos.add(new TableModify.TableInfoNode(srcNode, srcWithAlias,
@@ -5441,7 +5501,7 @@ private List buildUpdateSourceInfo(SqlUpdate call, Map t instanceof SqlDynamicParam);
RelNode valuesRel;
- if (values instanceof SqlValuesTableSource){
+ if (values instanceof SqlValuesTableSource) {
valuesRel = convertValues(bb, (SqlValuesTableSource) values, targetRowType);
- }else if (allIsDynamic) {
+ } else if (allIsDynamic) {
valuesRel = convertDynamicRowValues(bb, values, values.getOperandList(), true, targetRowType);
- }else {
+ } else {
valuesRel = convertRowValues(bb, values, values.getOperandList(), true, targetRowType);
}
@@ -6011,7 +6071,7 @@ private void convertValuesImpl(Blackboard bb, SqlCall values, RelDataType target
// ?
}
- private DynamicValues convertValues(Blackboard bb, SqlValuesTableSource values, RelDataType targetRowType){
+ private DynamicValues convertValues(Blackboard bb, SqlValuesTableSource values, RelDataType targetRowType) {
if (targetRowType == null) {
targetRowType = SqlTypeUtil.promoteToRowType(typeFactory, validator.getValidatedNodeType(values), null);
}
@@ -6024,14 +6084,13 @@ private DynamicValues convertValues(Blackboard bb, SqlValuesTableSource values,
}
tupleList.add(tuple.build());
}
- DynamicValues dynamicValues = DynamicValues.create(
+ DynamicValues dynamicValues = DynamicValues.create(
cluster,
cluster.traitSet().replace(RelDistributions.SINGLETON), //for mpp
targetRowType, tupleList.build());
return dynamicValues;
}
-
// ~ Inner Classes
// ----------------------------------------------------------
@@ -7739,6 +7798,8 @@ public interface Config {
* usage of OR in all cases.
*/
int getInSubQueryThreshold();
+
+ boolean isRemoveDistinct();
}
/**
@@ -7753,6 +7814,7 @@ public static class ConfigBuilder {
private boolean explain;
private boolean expand = true;
private int inSubQueryThreshold = DEFAULT_IN_SUB_QUERY_THRESHOLD;
+ private boolean removeDistinct = true;
private ConfigBuilder() {
}
@@ -7768,6 +7830,7 @@ public ConfigBuilder withConfig(Config config) {
this.explain = config.isExplain();
this.expand = config.isExpand();
this.inSubQueryThreshold = config.getInSubQueryThreshold();
+ this.removeDistinct = config.isRemoveDistinct();
return this;
}
@@ -7811,12 +7874,17 @@ public ConfigBuilder withInSubQueryThreshold(int inSubQueryThreshold) {
return this;
}
+ public ConfigBuilder withRemoveDistinct(boolean removeDistinct) {
+ this.removeDistinct = removeDistinct;
+ return this;
+ }
+
/**
* Builds a {@link Config}.
*/
public Config build() {
return new ConfigImpl(convertTableAccess, decorrelationEnabled, trimUnusedFields, createValuesRel, explain,
- expand, inSubQueryThreshold);
+ expand, inSubQueryThreshold, removeDistinct);
}
}
@@ -7833,9 +7901,11 @@ private static class ConfigImpl implements Config {
private final boolean explain;
private final int inSubQueryThreshold;
private final boolean expand;
+ private final boolean removeDistinct;
private ConfigImpl(boolean convertTableAccess, boolean decorrelationEnabled, boolean trimUnusedFields,
- boolean createValuesRel, boolean explain, boolean expand, int inSubQueryThreshold) {
+ boolean createValuesRel, boolean explain, boolean expand, int inSubQueryThreshold,
+ boolean removeDistinct) {
this.convertTableAccess = convertTableAccess;
this.decorrelationEnabled = decorrelationEnabled;
this.trimUnusedFields = trimUnusedFields;
@@ -7843,6 +7913,7 @@ private ConfigImpl(boolean convertTableAccess, boolean decorrelationEnabled, boo
this.explain = explain;
this.expand = expand;
this.inSubQueryThreshold = inSubQueryThreshold;
+ this.removeDistinct = removeDistinct;
}
public boolean isConvertTableAccess() {
@@ -7872,6 +7943,10 @@ public boolean isExpand() {
public int getInSubQueryThreshold() {
return inSubQueryThreshold;
}
+
+ public boolean isRemoveDistinct() {
+ return removeDistinct;
+ }
}
private static class AliasContext {
@@ -7903,7 +7978,7 @@ public static class HintBlackboard {
private final Deque aliasStack = new ArrayDeque<>();
- private final Deque asOfStack = new ArrayDeque<>();
+ private final Deque> asOfStack = new ArrayDeque<>();
public void beginSelect() {
hintStack.push(new HashMap<>(2));
@@ -7925,11 +8000,11 @@ public Map currentGroups() {
return hintStack.peek();
}
- public void beginAsOf(RexNode flashback) {
+ public void beginAsOf(Pair flashback) {
asOfStack.push(flashback);
}
- public RexNode endAsOf() {
+ public Pair endAsOf() {
return this.asOfStack.pop();
}
@@ -7937,7 +8012,7 @@ public boolean hasAsOf() {
return !asOfStack.isEmpty();
}
- public RexNode peekAsOf() {
+ public Pair peekAsOf() {
return this.asOfStack.peek();
}
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/tools/RelBuilder.java b/polardbx-calcite/src/main/java/org/apache/calcite/tools/RelBuilder.java
index ae8f5aab1..6a8bcb165 100644
--- a/polardbx-calcite/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -16,6 +16,14 @@
*/
package org.apache.calcite.tools;
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.plan.Context;
import org.apache.calcite.plan.Contexts;
@@ -28,14 +36,33 @@
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.core.*;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.CorrelationId;
+import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.core.TableModify;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.core.Values;
import org.apache.calcite.rel.logical.LogicalSemiJoin;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
-import org.apache.calcite.rex.*;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexSimplify;
+import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.server.CalciteServerStatement;
@@ -52,20 +79,12 @@
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Litmus;
import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Optionality;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.mapping.Mapping;
import org.apache.calcite.util.mapping.Mappings;
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
import javax.annotation.Nonnull;
import java.math.BigDecimal;
import java.util.AbstractList;
@@ -910,13 +929,14 @@ public RelBuilder scan(Iterable tableNames) {
return this;
}
- public RelBuilder flashback(RexNode flashback) {
+ public RelBuilder flashback(RexNode flashback, SqlOperator flashbackOperator) {
if (stack.peek() == null) {
return this;
}
RelNode last = stack.peek().rel;
- if (last instanceof TableScan){
- ((TableScan)last).setFlashback(flashback);
+ if (last instanceof TableScan) {
+ ((TableScan) last).setFlashback(flashback);
+ ((TableScan) last).setFlashbackOperator(flashbackOperator);
}
return this;
}
@@ -2146,7 +2166,10 @@ private static class AggCallImpl implements AggCall {
boolean approximate, RexNode filter,
String alias, ImmutableList operands) {
this.aggFunction = aggFunction;
- this.distinct = distinct;
+ // If the aggregate function ignores DISTINCT,
+ // make the DISTINCT flag FALSE.
+ this.distinct = distinct
+ && aggFunction.getDistinctOptionality() != Optionality.IGNORED;
this.approximate = approximate;
this.filter = filter;
this.alias = alias;
diff --git a/polardbx-calcite/src/main/java/org/apache/calcite/util/Optionality.java b/polardbx-calcite/src/main/java/org/apache/calcite/util/Optionality.java
new file mode 100644
index 000000000..2e34dbd2e
--- /dev/null
+++ b/polardbx-calcite/src/main/java/org/apache/calcite/util/Optionality.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.calcite.util;
+
+/**
+ * Four states that describe whether a particular behavior or
+ * property is allowed and/or not allowed.
+ */
+public enum Optionality {
+ /** A property is mandatory if an instance must possess it;
+ * it is an error if it does not. */
+ MANDATORY,
+
+ /** A property is optional if an instance may or may not possess it;
+ * neither state is an error. */
+ OPTIONAL,
+
+ /** A property is ignored if an instance may or may not possess it;
+ * if it possesses the property, the effect is as if it does not. */
+ IGNORED,
+
+ /** A property is forbidden if an instance must not possess it;
+ * it is an error if the instance has the property. */
+ FORBIDDEN
+}
diff --git a/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/BuildForeignKeyNameTest.java b/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/BuildForeignKeyNameTest.java
new file mode 100644
index 000000000..ea4dffee5
--- /dev/null
+++ b/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/BuildForeignKeyNameTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.sql.SqlCreateTable;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+
+public class BuildForeignKeyNameTest {
+
+ @Test
+ public void testBuildForeignKeyName() {
+ String fkName1 = "tab_ibfk_1";
+ String fkName2 = " tab_ibfk_2";
+ String fkName3 = " a tab_ibfk_3";
+
+ Assert.assertEquals("`tab_ibfk_1`", SqlCreateTable.buildForeignKeyName(fkName1, new HashSet<>(),""));
+ Assert.assertEquals("` tab_ibfk_2`", SqlCreateTable.buildForeignKeyName(fkName2, new HashSet<>(),""));
+ Assert.assertEquals("` a tab_ibfk_3`", SqlCreateTable.buildForeignKeyName(fkName3, new HashSet<>(),""));
+ }
+}
diff --git a/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java b/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
index b8f624390..262012405 100644
--- a/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
+++ b/polardbx-calcite/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
@@ -364,6 +364,20 @@ public class SqlTypeNameTest {
null,
tn);
}
+
+ @Test public void testSigned() {
+ SqlTypeName tn = SqlTypeName.get("SIGNED");
+ assertEquals(SqlTypeName.SIGNED, tn);
+
+ tn = SqlTypeName.get("SIGNED INTEGER");
+ assertEquals(SqlTypeName.SIGNED, tn);
+
+ tn = SqlTypeName.get("UNSIGNED");
+ assertEquals(SqlTypeName.UNSIGNED, tn);
+
+ tn = SqlTypeName.get("UNSIGNED INTEGER");
+ assertEquals(SqlTypeName.UNSIGNED, tn);
+ }
}
// End SqlTypeNameTest.java
diff --git a/polardbx-calcite/src/test/java/org/apache/calcite/sql/validate/ColumnarForbidTest.java b/polardbx-calcite/src/test/java/org/apache/calcite/sql/validate/ColumnarForbidTest.java
new file mode 100644
index 000000000..53a12bbc1
--- /dev/null
+++ b/polardbx-calcite/src/test/java/org/apache/calcite/sql/validate/ColumnarForbidTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+package org.apache.calcite.sql.validate;
+
+import com.alibaba.polardbx.common.exception.TddlRuntimeException;
+import org.apache.calcite.sql.SqlColumnDeclaration;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ColumnarForbidTest {
+
+ @Test(expected = TddlRuntimeException.class)
+ public void ForbidCitableModifyUnsupportedType() {
+ SqlIdentifier sqlIdentifier = mock(SqlIdentifier.class);
+ SqlColumnDeclaration sqlColumnDeclaration = mock(SqlColumnDeclaration.class);
+ SqlDataTypeSpec sqlDataTypeSpec = mock(SqlDataTypeSpec.class);
+
+ when(sqlColumnDeclaration.getDataType()).thenReturn(sqlDataTypeSpec);
+ when(sqlDataTypeSpec.getTypeName()).thenReturn(sqlIdentifier);
+ when(sqlIdentifier.getLastName()).thenReturn("binary");
+
+ SqlValidatorImpl.validateUnsupportedTypeWithCciWhenModifyColumn(sqlColumnDeclaration);
+ }
+
+ @Test
+ public void ForbidCitableModifySupportedType() {
+ SqlIdentifier sqlIdentifier = mock(SqlIdentifier.class);
+ SqlColumnDeclaration sqlColumnDeclaration = mock(SqlColumnDeclaration.class);
+ SqlDataTypeSpec sqlDataTypeSpec = mock(SqlDataTypeSpec.class);
+
+ when(sqlColumnDeclaration.getDataType()).thenReturn(sqlDataTypeSpec);
+ when(sqlDataTypeSpec.getTypeName()).thenReturn(sqlIdentifier);
+ when(sqlIdentifier.getLastName()).thenReturn("char");
+
+ SqlValidatorImpl.validateUnsupportedTypeWithCciWhenModifyColumn(sqlColumnDeclaration);
+ }
+}
diff --git a/polardbx-common/pom.xml b/polardbx-common/pom.xml
index aafe2b2f4..9910129de 100644
--- a/polardbx-common/pom.xml
+++ b/polardbx-common/pom.xml
@@ -135,7 +135,7 @@
org.apache.hadoop
hadoop-client
- ${hadoop-client.version}
+ ${hadoop.version}
commons-logging
@@ -187,6 +187,11 @@
com.github.ben-manes.caffeine
caffeine
+
+ org.mockito
+ mockito-inline
+ test
+
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/Engine.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/Engine.java
index 972bf6d67..21639977a 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/Engine.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/Engine.java
@@ -32,6 +32,7 @@ public enum Engine {
LOCAL_DISK,
EXTERNAL_DISK,
S3,
+ ABS,
OSS,
NFS,
MEMORY;
@@ -57,6 +58,8 @@ public static boolean hasCache(Engine engine) {
case OSS:
case EXTERNAL_DISK:
case NFS:
+ case S3:
+ case ABS:
return true;
default:
return false;
@@ -73,6 +76,7 @@ public static boolean isFileStore(Engine engine) {
case EXTERNAL_DISK:
case S3:
case NFS:
+ case ABS:
return true;
default:
return false;
@@ -88,6 +92,8 @@ public static boolean supportColumnar(Engine engine) {
case LOCAL_DISK:
case EXTERNAL_DISK:
case NFS:
+ case S3:
+ case ABS:
return true;
default:
return false;
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/TddlConstants.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/TddlConstants.java
index 15a6d982f..99ca31c9a 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/TddlConstants.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/TddlConstants.java
@@ -84,4 +84,8 @@ public class TddlConstants {
public static final String FOREIGN_KEY_PREFIX = "";
public static final int LONG_ENOUGH_TIMEOUT_FOR_DDL_ON_XPROTO_CONN = 7 * 24 * 60 * 60 * 1000;
+
+ public static final String BLACK_LIST_CONF = "BLACK_LIST_CONF";
+
+ public static final String ENABLE_JAVA_UDF = "ENABLE_JAVA_UDF";
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/CollationName.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/CollationName.java
index 5cafe0c41..ae9e8574d 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/CollationName.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/CollationName.java
@@ -317,7 +317,10 @@ public enum CollationName {
// for utf8
UTF8_GENERAL_CI, UTF8_BIN, UTF8_UNICODE_CI, UTF8_GENERAL_MYSQL500_CI,
- // for utf8mb
+ // for utf8mb4 in MySQL 8.0
+ UTF8MB4_ZH_0900_AS_CS,
+
+ // for utf8mb4
UTF8MB4_GENERAL_CI, UTF8MB4_BIN, UTF8MB4_UNICODE_CI,
// for utf16
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/MySQLUnicodeUtils.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/MySQLUnicodeUtils.java
index 69122884e..13955b5f5 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/MySQLUnicodeUtils.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/charset/MySQLUnicodeUtils.java
@@ -16,14 +16,10 @@
package com.alibaba.polardbx.common.charset;
-import com.alibaba.polardbx.common.utils.GeneralUtil;
import io.airlift.slice.DynamicSliceOutput;
import io.airlift.slice.Slice;
import io.airlift.slice.SliceOutput;
-import java.nio.charset.Charset;
-import java.util.Optional;
-
public class MySQLUnicodeUtils {
public static byte[][] LATIN1_TO_UTF8_BYTES = {
{(byte) 0x00}, {(byte) 0x01}, {(byte) 0x02}, {(byte) 0x03}, {(byte) 0x04}, {(byte) 0x05}, {(byte) 0x06},
@@ -114,4 +110,25 @@ public static boolean utf8ToLatin1(byte[] buff, int begin, int end, byte[] res)
}
return isUtf8FromLatin1;
}
+
+ public static boolean utf8ToLatin1(Slice slice, byte[] res, int len) {
+ int pos = 0, begin = 0, end = slice.length();
+ boolean isUtf8FromLatin1 = true;
+ while (begin < end && pos < len) {
+ int uc1 = ((int) slice.getByte(begin++)) & 0xFF;
+ // 0xxxxxxx
+ if (uc1 < 0x80) {
+ res[pos++] = (byte) uc1;
+ } else if (begin < end) {
+ if (uc1 != 0xC2 && uc1 != 0xC3) {
+ isUtf8FromLatin1 = false;
+ }
+ int uc2 = ((int) slice.getByte(begin++)) & 0xFF;
+ res[pos++] = (byte) (((uc1 & 0x1f) << 6) | (uc2 ^ 0x80));
+ } else {
+ res[pos++] = (byte) 0xFF;
+ }
+ }
+ return isUtf8FromLatin1;
+ }
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/constants/ServerVariables.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/constants/ServerVariables.java
index 1472b9098..426149b6b 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/constants/ServerVariables.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/constants/ServerVariables.java
@@ -18,6 +18,7 @@
import com.alibaba.polardbx.common.cdc.CdcConstants;
import com.alibaba.polardbx.common.properties.ConnectionProperties;
+import com.alibaba.polardbx.common.properties.DynamicConfig;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang.StringUtils;
@@ -3667,6 +3668,10 @@ public static boolean isGlobalBanned(String variable) {
return globalBannedVariables.contains(variable.toLowerCase());
}
+ public static boolean isGlobalBlackList(String variable) {
+ return DynamicConfig.getInstance().getBlacklistConf().contains(variable.toLowerCase());
+ }
+
public static boolean isCdcGlobal(String variable) {
return StringUtils.startsWith(variable.toLowerCase(), CdcConstants.CONFIG_KEY_PREFIX);
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/ddl/newengine/DdlPlanState.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/ddl/newengine/DdlPlanState.java
index 0c2ff7381..125b822fb 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/ddl/newengine/DdlPlanState.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/ddl/newengine/DdlPlanState.java
@@ -21,7 +21,7 @@ public enum DdlPlanState {
INIT,
EXECUTING,
SUCCESS,
- TERMINATED
- ;
+ TERMINATED,
+ PAUSE_ON_NON_MAINTENANCE_WINDOW;
}
\ No newline at end of file
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/exception/code/ErrorCode.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/exception/code/ErrorCode.java
index aeaef6c29..d3512268e 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/exception/code/ErrorCode.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/exception/code/ErrorCode.java
@@ -708,6 +708,8 @@ public enum ErrorCode {
ERR_STATISTIC_JOB_INTERRUPTED(ErrorType.Optimizer, 4531),
+ ERR_IN_PRUNING(ErrorType.Optimizer, 4532),
+
// ============= executor 从4600下标开始================
//
ERR_FUNCTION(ErrorType.Executor, 4600),
@@ -1244,6 +1246,7 @@ public enum ErrorCode {
// ================= concurrency control Related Exceptions ===================
ERR_CCL(ErrorType.CCL, 9201),
+ ERR_CCL_RESCHEDULE(ErrorType.CCL, 9202),
ERR_LOGICAL_TABLE_UNSUPPORTED(ErrorType.Executor, 9203),
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/ITransactionPolicy.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/ITransactionPolicy.java
index 2b45c4b54..efa20b327 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/ITransactionPolicy.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/ITransactionPolicy.java
@@ -68,7 +68,9 @@ enum TransactionClass {
AUTO_COMMIT,
- AUTO_COMMIT_TSO;
+ AUTO_COMMIT_TSO,
+
+ ARCHIVE;
public boolean isA(EnumSet set) {
return set.contains(this);
@@ -80,14 +82,17 @@ public boolean isA(EnumSet set) {
TransactionClass.TSO,
TransactionClass.TSO_READONLY,
TransactionClass.AUTO_COMMIT_SINGLE_SHARD,
- TSO_2PC_OPT);
+ TSO_2PC_OPT,
+ TransactionClass.ARCHIVE);
public static final EnumSet EXPLICIT_TRANSACTION = EnumSet
.of(TransactionClass.XA,
TransactionClass.XA_TSO,
TransactionClass.TSO,
TransactionClass.ALLOW_READ_CROSS_DB,
- TSO_2PC_OPT);
+ TransactionClass.COBAR_STYLE,
+ TSO_2PC_OPT,
+ TransactionClass.ARCHIVE);
public static final EnumSet TSO_TRANSACTION = EnumSet
.of(TransactionClass.TSO,
@@ -110,7 +115,8 @@ public boolean isA(EnumSet set) {
.of(TransactionClass.XA,
TransactionClass.XA_TSO,
TransactionClass.TSO,
- TSO_2PC_OPT);
+ TSO_2PC_OPT,
+ TransactionClass.ARCHIVE);
public static final EnumSet SUPPORT_PARALLEL_GET_CONNECTION_TRANSACTION = EnumSet
.of(TransactionClass.XA,
@@ -119,7 +125,8 @@ public boolean isA(EnumSet set) {
TransactionClass.AUTO_COMMIT,
TransactionClass.AUTO_COMMIT_SINGLE_SHARD,
TransactionClass.AUTO_COMMIT_TSO,
- TransactionClass.TSO_READONLY);
+ TransactionClass.TSO_READONLY,
+ TransactionClass.ARCHIVE);
public static final EnumSet ALLOW_GROUP_PARALLELISM_WITHOUT_SHARE_READVIEW_TRANSACTION =
EnumSet.of(TransactionClass.AUTO_COMMIT,
@@ -131,6 +138,7 @@ public boolean isA(EnumSet set) {
NoTransaction NO_TRANSACTION = new NoTransaction();
DefaultPolicy XA = new DefaultPolicy(TransactionClass.XA);
Tso TSO = new Tso();
+ DefaultPolicy ARCHIVE = new DefaultPolicy(TransactionClass.ARCHIVE);
TransactionClass getTransactionType(boolean isAutoCommit, boolean isReadOnly);
@@ -259,6 +267,8 @@ static ITransactionPolicy of(String name) {
return ITransactionPolicy.ALLOW_READ_CROSS_DB;
case "NO_TRANSACTION":
return ITransactionPolicy.NO_TRANSACTION;
+ case "ARCHIVE":
+ return ITransactionPolicy.ARCHIVE;
default:
throw new TddlRuntimeException(ErrorCode.ERR_CONFIG, "Unknown transaction policy: " + name);
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/PruneRawString.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/PruneRawString.java
index 57b08b7ae..60264b93a 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/PruneRawString.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/PruneRawString.java
@@ -17,13 +17,10 @@
package com.alibaba.polardbx.common.jdbc;
import com.alibaba.polardbx.common.utils.GeneralUtil;
-import com.alibaba.polardbx.common.utils.TStringUtil;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import java.util.BitSet;
import java.util.List;
-import java.util.Set;
/**
* @author fangwu
@@ -88,11 +85,16 @@ public Object getObj(int index, int skIndex) {
@Override
public String display() {
- String rs = "PruneRaw(" + buildRawString() + ")";
- if (rs.length() > 4096) {
- return rs.substring(0, 4096) + "...";
+ StringBuilder stringBuilder = new StringBuilder();
+ if (size() == super.getObjList().size()) {
+ stringBuilder.append("NonPruneRaw(" + buildRawString() + ")");
+ } else {
+ stringBuilder.append("PruneRaw(" + buildRawString() + ")");
}
- return rs;
+ if (stringBuilder.length() > 4096) {
+ return stringBuilder.substring(0, 4096) + "...";
+ }
+ return stringBuilder.toString();
}
@Override
@@ -195,12 +197,16 @@ private void paramCheck() {
if (indexes == null || indexes.isEmpty()) {
GeneralUtil.nestedException("RawString init ERROR MUITI_INDEX mode with invalid indexes:" + indexes);
}
+ return;
default:
GeneralUtil.nestedException("RawString init ERROR mode invalid :" + pruneMode);
}
}
public void merge(PruneRawString pruneRawString) {
+ if (size() == super.getObjList().size()) {
+ return;
+ }
if (pruneMode == PRUNE_MODE.RANGE) {
transformModeToMultiIndex();
}
@@ -208,6 +214,11 @@ public void merge(PruneRawString pruneRawString) {
pruneRawString.transformModeToMultiIndex();
}
indexes.or(pruneRawString.indexes);
+ if (indexes.cardinality() == super.getObjList().size()) {
+ pruneMode = PRUNE_MODE.RANGE;
+ startIndex = 0;
+ endIndex = super.getObjList().size();
+ }
}
private void transformModeToMultiIndex() {
@@ -230,4 +241,29 @@ private void transformModeToMultiIndex() {
public enum PRUNE_MODE {
RANGE, MULTI_INDEX;
}
+
+ /**
+ * do the same thing as RawString.pruneStep, but return itself.
+ * WARNING: this method will change this PruneRawString itself.
+ */
+ @Override
+ public PruneRawString pruneStep(int curIndex) {
+ pruneMode = PruneRawString.PRUNE_MODE.RANGE;
+ startIndex = curIndex;
+ endIndex = curIndex + 1;
+ return this;
+ }
+
+ @Override
+ public PruneRawString clone() {
+ if (pruneMode == PRUNE_MODE.RANGE) {
+ return new PruneRawString(super.getObjList(), pruneMode, startIndex, endIndex, null);
+ } else {
+ return new PruneRawString(super.getObjList(), pruneMode, -1, -1, (BitSet) indexes.clone());
+ }
+ }
+
+ public int getSourceSize() {
+ return super.size();
+ }
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/RawString.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/RawString.java
index 86db3f3a2..3887908ca 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/RawString.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/RawString.java
@@ -210,4 +210,15 @@ public Object acquireObject(int subIndex, int skIndex) {
return getObj(subIndex, skIndex);
}
}
+
+ /**
+ * build one PruneRawString with one object(target by curIndex) inside this RawString
+ */
+ public PruneRawString pruneStep(int curIndex) {
+ return new PruneRawString(this.getObjList(), PruneRawString.PRUNE_MODE.RANGE, curIndex, curIndex + 1, null);
+ }
+
+ public RawString clone() {
+ return new RawString(this.getObjList());
+ }
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/TableName.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/TableName.java
index 314f9a7f3..d0f8c5165 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/TableName.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/jdbc/TableName.java
@@ -36,11 +36,6 @@ public String getTableName() {
return this.tableName;
}
- public void setTableName(String tableName) throws SQLException {
- this.checkName(tableName);
- this.tableName = tableName.trim();
- }
-
private void checkName(String tName) throws SQLException {
if (StringUtils.isEmptyOrWhitespaceOnly(tName)) {
throw new SQLException("tableName should not be empty", "S1009");
@@ -63,9 +58,6 @@ private void checkName(String tName) throws SQLException {
case '\u001a':
needsHexEscape = true;
break;
- case ' ':
- needsHexEscape = true;
- break;
case '"':
needsHexEscape = true;
break;
@@ -80,7 +72,6 @@ private void checkName(String tName) throws SQLException {
throw new SQLException("tableName format error: " + this.tableName, "S1009");
}
}
-
}
}
@@ -89,4 +80,3 @@ public String toString() {
return getTableName();
}
}
-
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/mock/MockUtils.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/mock/MockUtils.java
new file mode 100644
index 000000000..f62186de7
--- /dev/null
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/mock/MockUtils.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright [2013-2021], Alibaba Group Holding Limited
+ *
+ * Licensed 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.
+ */
+
+package com.alibaba.polardbx.common.mock;
+
+import java.lang.reflect.Field;
+
+public class MockUtils {
+
+ public interface ThrowableRunnable {
+ void run() throws Throwable;
+ }
+
+ public interface ThrowableConsumer {
+ void accept(T t) throws Throwable;
+ }
+
+ public static T assertThrows(Class expectedType,
+ String expectedMessage,
+ ThrowableRunnable methodCall) {
+ try {
+ methodCall.run();
+ } catch (Throwable e) {
+ if (expectedType.isInstance(e)) {
+ if (expectedMessage != null) {
+ if (!expectedMessage.equals(e.getMessage())) {
+ throw new AssertionError(
+ "Expected message: " + expectedMessage + ", actual: " + e.getMessage()
+ );
+ }
+ }
+ return (T) e;
+ }
+ throw new AssertionError("Expected exception: " + expectedType.getName(), e);
+ }
+ throw new AssertionError("Expected exception: " + expectedType.getName());
+ }
+
+ public static void setInternalState(Object target, String fieldName, Object value) {
+ try {
+ Field field = target.getClass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+ field.set(target, value);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/Constants.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/Constants.java
index ccf4358a4..df9921746 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/Constants.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/Constants.java
@@ -90,7 +90,9 @@ private Constants() {
public static final long MULTIPART_UPLOAD_PART_SIZE_DEFAULT =
104857600; // 100 MB
- /** The minimum multipart size which OSS supports. */
+ /**
+ * The minimum multipart size which OSS supports.
+ */
public static final int MULTIPART_MIN_SIZE = 100 * 1024;
public static final int MULTIPART_UPLOAD_PART_NUM_LIMIT = 10000;
@@ -155,4 +157,16 @@ private Constants() {
public static final String UPLOAD_ACTIVE_BLOCKS_KEY =
"fs.oss.upload.active.blocks";
public static final int UPLOAD_ACTIVE_BLOCKS_DEFAULT = 4;
+
+ // S3 access verification
+ public static final String S3_ACCESS_KEY = "fs.s3a.access.key";
+ public static final String S3_SECRET_KEY = "fs.s3a.secret.key";
+
+ // ABS access verification
+ // fs.azure.account.key..blob.
+ public static final String ABS_URI_SUFFIX_PATTERN = "%s.blob.%s";
+ public static final String ABS_ACCOUNT_KEY_PATTERN = "fs.azure.account.key." + ABS_URI_SUFFIX_PATTERN;
+
+ public static final String AZURE_WASBS_SCHEME = "wasbs";
+ public static final String AZURE_WASB_SCHEME = "wasb";
}
\ No newline at end of file
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/InputStreamWithRateLimiter.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/InputStreamWithRateLimiter.java
new file mode 100644
index 000000000..e03a8e772
--- /dev/null
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/InputStreamWithRateLimiter.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright [2013-2021], Alibaba Group Holding Limited
+ *
+ * Licensed 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.
+ */
+
+package com.alibaba.polardbx.common.oss.filesystem;
+
+import org.apache.hadoop.fs.PositionedReadable;
+import org.apache.hadoop.fs.Seekable;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class InputStreamWithRateLimiter extends InputStream implements Seekable, PositionedReadable {
+ final private FileSystemRateLimiter rateLimiter;
+ final private InputStream in;
+
+ public InputStreamWithRateLimiter(InputStream in, FileSystemRateLimiter rateLimiter) {
+ if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {
+ throw new IllegalArgumentException(
+ "In is not an instance of Seekable or PositionedReadable");
+ }
+ this.in = in;
+ this.rateLimiter = rateLimiter;
+ }
+
+ @Override
+ public synchronized int read() throws IOException {
+ rateLimiter.acquireRead(1);
+ return in.read();
+ }
+
+ @Override
+ public synchronized int read(byte @NotNull [] buf, int off, int len) throws IOException {
+ rateLimiter.acquireRead(len);
+ return in.read(buf, off, len);
+ }
+
+ @Override
+ public synchronized int read(byte @NotNull [] b) throws IOException {
+ rateLimiter.acquireRead(b.length);
+ return in.read(b);
+ }
+
+ @Override
+ public synchronized long skip(long n) throws IOException {
+ // TODO(siyun): should this be tracked by rate limiter?
+ return in.skip(n);
+ }
+
+ @Override
+ public synchronized int available() throws IOException {
+ return in.available();
+ }
+
+ @Override
+ public synchronized void close() throws IOException {
+ in.close();
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ in.mark(readlimit);
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ in.reset();
+ }
+
+ @Override
+ public synchronized boolean markSupported() {
+ return in.markSupported();
+ }
+
+ @Override
+ public int read(long position, byte[] buffer, int offset, int length) throws IOException {
+ rateLimiter.acquireRead(length);
+ return ((PositionedReadable) in).read(position, buffer, offset, length);
+ }
+
+ @Override
+ public void readFully(long position, byte[] buffer, int offset, int length) throws IOException {
+ rateLimiter.acquireRead(length);
+ ((PositionedReadable) in).readFully(position, buffer, offset, length);
+ }
+
+ @Override
+ public void readFully(long position, byte[] buffer) throws IOException {
+ rateLimiter.acquireRead(buffer.length);
+ ((PositionedReadable) in).readFully(position, buffer);
+ }
+
+ @Override
+ public void seek(long pos) throws IOException {
+ ((Seekable) in).seek(pos);
+ }
+
+ @Override
+ public long getPos() throws IOException {
+ return ((Seekable) in).getPos();
+ }
+
+ @Override
+ public boolean seekToNewSource(long targetPos) throws IOException {
+ return ((Seekable) in).seekToNewSource(targetPos);
+ }
+
+ public InputStream getWrappedStream() {
+ return in;
+ }
+}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/NFSFileSystem.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/NFSFileSystem.java
index 1a9af7af0..4f4a7cd3c 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/NFSFileSystem.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/NFSFileSystem.java
@@ -47,7 +47,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;
-public class NFSFileSystem extends FileSystem {
+public class NFSFileSystem extends FileSystem implements RateLimitable {
private static final Logger LOG =
LoggerFactory.getLogger(NFSFileSystem.class);
@@ -380,6 +380,7 @@ public FileStatus getFileStatusImpl(Path path) throws IOException {
}
}
+ @Override
public FileSystemRateLimiter getRateLimiter() {
return this.rateLimiter;
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OSSFileSystem.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OSSFileSystem.java
index f250c08fb..3289c7e40 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OSSFileSystem.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OSSFileSystem.java
@@ -74,7 +74,7 @@
/**
* To access OSS blob system in a filesystem style.
*/
-public class OSSFileSystem extends FileSystem {
+public class OSSFileSystem extends FileSystem implements RateLimitable {
private static final Logger LOG =
LoggerFactory.getLogger(OSSFileSystem.class);
private URI uri;
@@ -348,6 +348,7 @@ public FileStatus getFileStatusImpl(Path path) throws IOException {
}
}
+ @Override
public FileSystemRateLimiter getRateLimiter() {
return this.rateLimiter;
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OutputStreamWithRateLimiter.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OutputStreamWithRateLimiter.java
new file mode 100644
index 000000000..89f31b0c0
--- /dev/null
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/OutputStreamWithRateLimiter.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright [2013-2021], Alibaba Group Holding Limited
+ *
+ * Licensed 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.
+ */
+
+package com.alibaba.polardbx.common.oss.filesystem;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class OutputStreamWithRateLimiter extends OutputStream {
+ final private FileSystemRateLimiter rateLimiter;
+ final private OutputStream out;
+
+ public OutputStreamWithRateLimiter(OutputStream out, FileSystemRateLimiter rateLimiter) {
+ this.out = out;
+ this.rateLimiter = rateLimiter;
+ }
+
+ @Override
+ public synchronized void write(byte @NotNull [] b) throws IOException {
+ rateLimiter.acquireWrite(b.length);
+ out.write(b);
+ }
+
+ @Override
+ public synchronized void write(byte @NotNull [] b, int off, int len) throws IOException {
+ rateLimiter.acquireWrite(len);
+ out.write(b, off, len);
+ }
+
+ @Override
+ public synchronized void flush() throws IOException {
+ out.flush();
+ }
+
+ @Override
+ public synchronized void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public synchronized void write(int b) throws IOException {
+ rateLimiter.acquireWrite(1);
+ out.write(b);
+ }
+
+ public OutputStream getWrappedStream() {
+ return out;
+ }
+}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/RateLimitable.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/RateLimitable.java
new file mode 100644
index 000000000..907c940f5
--- /dev/null
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/oss/filesystem/RateLimitable.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright [2013-2021], Alibaba Group Holding Limited
+ *
+ * Licensed 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.
+ */
+
+package com.alibaba.polardbx.common.oss.filesystem;
+
+public interface RateLimitable {
+ FileSystemRateLimiter getRateLimiter();
+}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/partition/MurmurHashUtils.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/partition/MurmurHashUtils.java
index ca0c5142e..9f8882e28 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/partition/MurmurHashUtils.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/partition/MurmurHashUtils.java
@@ -33,20 +33,32 @@ private static long murmurHash3_128(byte[] data, int seed) {
return longVal;
}
- private static final HashFunction zeroSeedMurmur3hashFunc = Hashing.murmur3_128(0);
+ private static int murmurHash3_32(byte[] data) {
+ HashCode hashCode = zeroSeedMurmur3hashFunc32.hashBytes(data);
+ int intVal = hashCode.asInt();
+ return intVal;
+ }
+
+ private static final HashFunction zeroSeedMurmur3hashFunc32 = Hashing.murmur3_32(0);
+
+ private static final HashFunction zeroSeedMurmur3hashFunc128 = Hashing.murmur3_128(0);
private static long murmurHash3_128(long data) {
- HashCode hashCode = zeroSeedMurmur3hashFunc.hashLong(data);
+ HashCode hashCode = zeroSeedMurmur3hashFunc128.hashLong(data);
long longVal = hashCode.asLong();
return longVal;
}
- public static long murmurHashWithZeroSeed(byte[] data) {
+ public static long murmurHash128WithZeroSeed(long data) {
+ return murmurHash3_128(data);
+ }
+
+ public static long murmurHash128WithZeroSeed(byte[] data) {
return murmurHash3_128(data, 0);
}
- public static long murmurHashWithZeroSeed(long data) {
- return murmurHash3_128(data);
+ public static int murmurHash32WithZeroSeed(byte[] data) {
+ return murmurHash3_32(data);
}
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionParams.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionParams.java
index ca33c6622..64ad01c15 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionParams.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionParams.java
@@ -360,7 +360,7 @@ public class ConnectionParams {
new IntConfigParam(ConnectionProperties.PHYSICAL_DDL_MDL_WAITING_TIMEOUT,
-1, //5
Attribute.MAX_PHYSICAL_DDL_MDL_WAITING_TIMEOUT, //Integer.MAX_VALUE
- Integer.valueOf(Attribute.PHYSICAL_DDL_MDL_WAITING_TIMEOUT), //15
+ -1,
false);
/**
@@ -1253,6 +1253,11 @@ public static void addSupportedParam(ConfigParam param) {
true,
false);
+ public final static BooleanConfigParam BACKFILL_USE_RETURNING = new BooleanConfigParam(
+ ConnectionProperties.BACKFILL_USE_RETURNING,
+ true,
+ false);
+
/**
* enable parallel physical table backfill
*/
@@ -2036,6 +2041,9 @@ public static void addSupportedParam(ConfigParam param) {
public static final BooleanConfigParam ENABLE_LV_SUBQUERY_UNWRAP = new BooleanConfigParam(
ConnectionProperties.ENABLE_LV_SUBQUERY_UNWRAP, true, true);
+ public static final BooleanConfigParam EXPLAIN_PRUNING_DETAIL = new BooleanConfigParam(
+ ConnectionProperties.EXPLAIN_PRUNING_DETAIL, false, true);
+
public static final BooleanConfigParam ENABLE_FILTER_REORDER = new BooleanConfigParam(
ConnectionProperties.ENABLE_FILTER_REORDER, true, true);
@@ -2626,6 +2634,11 @@ public static void addSupportedParam(ConfigParam param) {
true,
true);
+ public static final BooleanConfigParam ENABLE_PUSHDOWN_DISTINCT = new BooleanConfigParam(
+ ConnectionProperties.ENABLE_PUSHDOWN_DISTINCT,
+ true,
+ true);
+
public static final BooleanConfigParam ENABLE_INDEX_SKYLINE = new BooleanConfigParam(
ConnectionProperties.ENABLE_INDEX_SKYLINE,
false,
@@ -2692,18 +2705,6 @@ public static void addSupportedParam(ConfigParam param) {
true
);
- public static final BooleanConfigParam ENABLE_JAVA_UDF = new BooleanConfigParam(
- ConnectionProperties.ENABLE_JAVA_UDF,
- true,
- true
- );
-
- public static final BooleanConfigParam CHECK_INVALID_JAVA_UDF = new BooleanConfigParam(
- ConnectionProperties.CHECK_INVALID_JAVA_UDF,
- true,
- true
- );
-
public static final LongConfigParam MAX_JAVA_UDF_NUM = new LongConfigParam(
ConnectionProperties.MAX_JAVA_UDF_NUM,
0L,
@@ -3074,7 +3075,7 @@ public static class ConnectionParamValues {
public static final IntConfigParam IN_SUB_QUERY_THRESHOLD = new IntConfigParam(
ConnectionProperties.IN_SUB_QUERY_THRESHOLD, 2, Integer.MAX_VALUE,
- 8, true);
+ 100000, true);
public static final BooleanConfigParam ENABLE_IN_SUB_QUERY_FOR_DML = new BooleanConfigParam(
ConnectionProperties.ENABLE_IN_SUB_QUERY_FOR_DML, false, Boolean.TRUE);
@@ -3255,6 +3256,14 @@ public static class ConnectionParamValues {
false,
true);
+ /**
+ * Label if auto use key syntax for all local index on show create table
+ */
+ public static final BooleanConfigParam ENABLE_USE_KEY_FOR_ALL_LOCAL_INDEX = new BooleanConfigParam(
+ ConnectionProperties.ENABLE_USE_KEY_FOR_ALL_LOCAL_INDEX,
+ false,
+ true);
+
/**
* Label if auto use range/list columns partitions for "part by range/list", default is true
*/
@@ -3503,6 +3512,9 @@ public static class ConnectionParamValues {
public static final BooleanConfigParam ENABLE_NDV_USE_COLUMNAR = new BooleanConfigParam(
ConnectionProperties.ENABLE_NDV_USE_COLUMNAR, false, true);
+ public static final BooleanConfigParam ENABLE_MPP_NDV_USE_COLUMNAR = new BooleanConfigParam(
+ ConnectionProperties.ENABLE_MPP_NDV_USE_COLUMNAR, false, true);
+
/**
* expire time(sec) for ndv sketch info
*/
@@ -3660,7 +3672,7 @@ public static class ConnectionParamValues {
new IntConfigParam(ConnectionProperties.CHANGE_SET_APPLY_BATCH, 1, 10 * 1024, 128, false);
public static final LongConfigParam CHANGE_SET_MEMORY_LIMIT = new LongConfigParam(
- ConnectionProperties.CHANGE_SET_MEMORY_LIMIT, 1024L, 1024 * 1024 * 1024L, 8 * 1024 * 1024L, false);
+ ConnectionProperties.CHANGE_SET_MEMORY_LIMIT, 1024L, 16 * 1024 * 1024L, 1024 * 1024L, false);
public static final BooleanConfigParam CN_ENABLE_CHANGESET =
new BooleanConfigParam(ConnectionProperties.CN_ENABLE_CHANGESET, true, true);
@@ -3886,19 +3898,10 @@ public static class ConnectionParamValues {
true);
/**
- * the min size of IN expr that would be pruned
- */
- public static final IntConfigParam IN_PRUNE_SIZE = new IntConfigParam(
- ConnectionProperties.IN_PRUNE_SIZE, 0, Integer.MAX_VALUE, 150, true);
-
- /**
- * the batch size of IN expr being pruned
+ * the MAX size of IN expr being pruned
*/
- public static final IntConfigParam IN_PRUNE_STEP_SIZE = new IntConfigParam(
- ConnectionProperties.IN_PRUNE_STEP_SIZE, 1, Integer.MAX_VALUE, 10, true);
-
public static final IntConfigParam IN_PRUNE_MAX_TIME = new IntConfigParam(
- ConnectionProperties.IN_PRUNE_MAX_TIME, 1, Integer.MAX_VALUE, 100, true);
+ ConnectionProperties.IN_PRUNE_MAX_TIME, 1, Integer.MAX_VALUE, 100000, true);
public static final IntConfigParam MAX_IN_PRUNE_CACHE_SIZE = new IntConfigParam(
ConnectionProperties.MAX_IN_PRUNE_CACHE_SIZE, 0, Integer.MAX_VALUE, 200, true);
@@ -3940,6 +3943,16 @@ public static class ConnectionParamValues {
false,
false);
+ public static final BooleanConfigParam OUTPUT_MYSQL_ERROR_CODE =
+ new BooleanConfigParam(ConnectionProperties.OUTPUT_MYSQL_ERROR_CODE,
+ false,
+ false);
+
+ public static final StringConfigParam MAPPING_TO_MYSQL_ERROR_CODE =
+ new StringConfigParam(ConnectionProperties.MAPPING_TO_MYSQL_ERROR_CODE,
+ "",
+ false);
+
public static final StringConfigParam PURGE_OSS_FILE_CRON_EXPR = new StringConfigParam(
ConnectionProperties.PURGE_OSS_FILE_CRON_EXPR, "0 0 1 ? * WED", true);
@@ -4571,9 +4584,35 @@ public static class ConnectionParamValues {
public static final BooleanConfigParam PHYSICAL_BACKFILL_SPEED_TEST = new BooleanConfigParam(
ConnectionProperties.PHYSICAL_BACKFILL_SPEED_TEST,
+ false,
+ true);
+
+ /**
+ * rebalance start point
+ */
+ public static final BooleanConfigParam REBALANCE_MAINTENANCE_ENABLE = new BooleanConfigParam(
+ ConnectionProperties.REBALANCE_MAINTENANCE_ENABLE,
true,
true);
+ /**
+ * rebalance start point
+ */
+ public static final StringConfigParam REBALANCE_MAINTENANCE_TIME_START =
+ new StringConfigParam(ConnectionProperties.REBALANCE_MAINTENANCE_TIME_START, "00:00", true);
+
+ /**
+ * rebalance stop point
+ */
+ public static final StringConfigParam REBALANCE_MAINTENANCE_TIME_END =
+ new StringConfigParam(ConnectionProperties.REBALANCE_MAINTENANCE_TIME_END, "00:00", true);
+
+ public static final BooleanConfigParam CANCEL_REBALANCE_JOB_DUE_MAINTENANCE = new BooleanConfigParam(
+ ConnectionProperties.CANCEL_REBALANCE_JOB_DUE_MAINTENANCE,
+ false,
+ true
+ );
+
public static final BooleanConfigParam ENABLE_DEADLOCK_DETECTION_80 = new BooleanConfigParam(
ConnectionProperties.ENABLE_DEADLOCK_DETECTION_80,
false,
@@ -4818,6 +4857,12 @@ public static class ConnectionParamValues {
true
);
+ public static final BooleanConfigParam ENABLE_1PC_OPT = new BooleanConfigParam(
+ ConnectionProperties.ENABLE_1PC_OPT,
+ true,
+ true
+ );
+
public static final BooleanConfigParam ENABLE_SINGLE_SHARD_WRITE = new BooleanConfigParam(
ConnectionProperties.ENABLE_SINGLE_SHARD_WRITE, true, true);
}
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionProperties.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionProperties.java
index 09b0ad82a..5c89c64dd 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionProperties.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/ConnectionProperties.java
@@ -684,10 +684,6 @@ public class ConnectionProperties {
public static final String ENABLE_UDF = "ENABLE_UDF";
- public static final String ENABLE_JAVA_UDF = "ENABLE_JAVA_UDF";
-
- public static final String CHECK_INVALID_JAVA_UDF = "CHECK_INVALID_JAVA_UDF";
-
public static final String MAX_JAVA_UDF_NUM = "MAX_JAVA_UDF_NUM";
public static final String FORCE_DROP_JAVA_UDF = "FORCE_DROP_JAVA_UDF";
@@ -865,6 +861,8 @@ public class ConnectionProperties {
public static final String ENABLE_LV_SUBQUERY_UNWRAP = "ENABLE_LV_SUBQUERY_UNWRAP";
+ public static final String EXPLAIN_PRUNING_DETAIL = "EXPLAIN_PRUNING_DETAIL";
+
public static final String ENABLE_FILTER_REORDER = "ENABLE_FILTER_REORDER";
public static final String ENABLE_CONSTANT_FOLD = "ENABLE_CONSTANT_FOLD";
@@ -1095,6 +1093,8 @@ public class ConnectionProperties {
*/
public static final String BACKFILL_MAX_SAMPLE_SIZE = "BACKFILL_MAX_SAMPLE_SIZE";
+ public static final String BACKFILL_USE_RETURNING = "BACKFILL_USE_RETURNING";
+
/**
* enable split physical table for backfill
*/
@@ -1802,6 +1802,11 @@ public class ConnectionProperties {
*/
public static final String ENABLE_COMPLEX_DML_CROSS_DB = "ENABLE_COMPLEX_DML_CROSS_DB";
public static final String COMPLEX_DML_WITH_TRX = "COMPLEX_DML_WITH_TRX";
+
+ public static final String ENABLE_PUSHDOWN_DISTINCT = "ENABLE_PUSHDOWN_DISTINCT";
+ /**
+ * Enable index selection
+ */
public static final String ENABLE_INDEX_SELECTION = "ENABLE_INDEX_SELECTION";
public static final String ENABLE_INDEX_SELECTION_PRUNE = "ENABLE_INDEX_SELECTION_PRUNE";
@@ -2055,6 +2060,11 @@ public class ConnectionProperties {
* Label if auto use range-key subpart for index of auto-part table, default is true
*/
public static final String ENABLE_AUTO_USE_RANGE_FOR_TIME_INDEX = "ENABLE_AUTO_USE_RANGE_FOR_TIME_INDEX";
+ /**
+ * Label if auto use key syntax for all local index on show create table
+ */
+ public static final String ENABLE_USE_KEY_FOR_ALL_LOCAL_INDEX = "ENABLE_USE_KEY_FOR_ALL_LOCAL_INDEX";
+
/**
* Label if auto use range/list columns partitions for "part by range/list", default is true
*/
@@ -2158,6 +2168,8 @@ public class ConnectionProperties {
public static final String ENABLE_HA_CHECK_TASK_LOG = "ENABLE_HA_CHECK_TASK_LOG";
public static final String ENABLE_NDV_USE_COLUMNAR = "ENABLE_NDV_USE_COLUMNAR";
+
+ public static final String ENABLE_MPP_NDV_USE_COLUMNAR = "ENABLE_MPP_NDV_USE_COLUMNAR";
/**
* ndv sketch expire time
*/
@@ -2328,6 +2340,12 @@ public class ConnectionProperties {
*/
public static final String IN_PRUNE_STEP_SIZE = "IN_PRUNE_STEP_SIZE";
public static final String IN_PRUNE_MAX_TIME = "IN_PRUNE_MAX_TIME";
+ public static final String PRUNING_TIME_WARNING_THRESHOLD = "PRUNING_TIME_WARNING_THRESHOLD";
+
+ public static final String ENABLE_PRUNING_IN = "ENABLE_PRUNING_IN";
+
+ public static final String ENABLE_PRUNING_IN_DML = "ENABLE_PRUNING_IN_DML";
+
/**
* the max num of pruning info cache by logical view
*/
@@ -2377,6 +2395,10 @@ public class ConnectionProperties {
public static final String ENABLE_STANDBY_BACKFILL = "ENABLE_STANDBY_BACKFILL";
public static final String PHYSICAL_DDL_IGNORED_ERROR_CODE = "PHYSICAL_DDL_IGNORED_ERROR_CODE";
public static final String DDL_PAUSE_DURING_EXCEPTION = "DDL_PAUSE_DURING_EXCEPTION";
+ public static final String OUTPUT_MYSQL_ERROR_CODE = "OUTPUT_MYSQL_ERROR_CODE";
+
+ public static final String MAPPING_TO_MYSQL_ERROR_CODE = "MAPPING_TO_MYSQL_ERROR_CODE";
+
public static final String CHANGE_SET_REPLAY_TIMES = "CHANGE_SET_REPLAY_TIMES";
public static final String CHANGE_SET_APPLY_BATCH = "CHANGE_SET_APPLY_BATCH";
public static final String CHANGE_SET_MEMORY_LIMIT = "CHANGE_SET_MEMORY_LIMIT";
@@ -2601,6 +2623,13 @@ public class ConnectionProperties {
public static final String PHYSICAL_BACKFILL_SPEED_TEST =
"PHYSICAL_BACKFILL_SPEED_TEST";
+ public static final String REBALANCE_MAINTENANCE_ENABLE = "REBALANCE_MAINTENANCE_ENABLE";
+ public static final String REBALANCE_MAINTENANCE_TIME_START = "REBALANCE_MAINTENANCE_TIME_START";
+
+ public static final String REBALANCE_MAINTENANCE_TIME_END = "REBALANCE_MAINTENANCE_TIME_END";
+
+ public static final String CANCEL_REBALANCE_JOB_DUE_MAINTENANCE = "CANCEL_REBALANCE_JOB_DUE_MAINTENANCE";
+
public static final String ENABLE_DEADLOCK_DETECTION_80 = "ENABLE_DEADLOCK_DETECTION_80";
public static final String MOCK_COLUMNAR_INDEX = "MOCK_COLUMNAR_INDEX";
public static final String MCI_FORMAT = "MCI_FORMAT";
diff --git a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/DynamicConfig.java b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/DynamicConfig.java
index c6fc8786f..2c170fbd7 100644
--- a/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/DynamicConfig.java
+++ b/polardbx-common/src/main/java/com/alibaba/polardbx/common/properties/DynamicConfig.java
@@ -16,13 +16,23 @@
package com.alibaba.polardbx.common.properties;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.alibaba.fastjson.parser.Feature;
+import com.alibaba.polardbx.common.TddlConstants;
import com.alibaba.polardbx.common.constants.IsolationLevel;
import com.alibaba.polardbx.common.statementsummary.StatementSummaryManager;
import com.alibaba.polardbx.common.utils.version.InstanceVersion;
+import com.alibaba.polardbx.common.utils.TStringUtil;
import com.alibaba.polardbx.config.ConfigDataMode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import java.util.regex.Pattern;
/**
@@ -336,21 +346,47 @@ public void loadValue(Logger logger, String key, String value) {
case ConnectionProperties.ENABLE_TRX_DEBUG_MODE:
enableTrxDebugMode = parseValue(value, Boolean.class, false);
break;
- case ConnectionProperties.ENABLE_MQ_CACHE_COST_BY_THREAD:
- enableMQCacheByThread = parseValue(value, Boolean.class, true);
- break;
case ConnectionProperties.INSTANCE_READ_ONLY:
instanceReadOnly = parseValue(value, Boolean.class, false);
break;
- case ConnectionProperties.ENABLE_1PC_OPT:
- enable1PcOpt = parseValue(value, Boolean.class, true);
- break;
case ConnectionProperties.MIN_SNAPSHOT_KEEP_TIME:
minSnapshotKeepTime = parseValue(value, Integer.class, 5 * 60 * 1000);
break;
case ConnectionProperties.FORBID_AUTO_COMMIT_TRX:
forbidAutoCommitTrx = parseValue(value, Boolean.class, false);
break;
+ case ConnectionProperties.MAPPING_TO_MYSQL_ERROR_CODE:
+ errorCodeMapping = initErrorCodeMapping(value);
+ break;
+ case ConnectionProperties.PRUNING_TIME_WARNING_THRESHOLD:
+ pruningTimeWarningThreshold = parseValue(value, Long.class, 500L);
+ break;
+ case ConnectionProperties.ENABLE_PRUNING_IN:
+ enablePruningIn = parseValue(value, Boolean.class, true);
+ break;
+ case ConnectionProperties.ENABLE_PRUNING_IN_DML:
+ enablePruningInDml = parseValue(value, Boolean.class, true);
+ break;
+ case ConnectionProperties.ENABLE_MQ_CACHE_COST_BY_THREAD:
+ enableMQCacheByThread = parseValue(value, Boolean.class, true);
+ break;
+ case ConnectionProperties.ENABLE_USE_KEY_FOR_ALL_LOCAL_INDEX:
+ enableUseKeyForAllLocalIndex = parseValue(value, Boolean.class, false);
+ break;
+ case TddlConstants.BLACK_LIST_CONF:
+ String blockLists = parseValue(value, String.class, "");
+ List tempBlackList = new ArrayList<>();
+ if (StringUtils.isNotBlank(blockLists)) {
+ String[] blockListArr = blockLists.split(",");
+ for (String blockList : blockListArr) {
+ if (StringUtils.isNotBlank(blockList)) {
+ tempBlackList.add(blockList.toLowerCase(Locale.ROOT));
+ }
+ }
+ }
+ blackListConf = tempBlackList;
+ break;
+
default:
FileConfig.getInstance().loadValue(logger, key, value);
break;
@@ -644,7 +680,8 @@ public boolean isEnableAutoUseRangeForTimeIndex() {
}
private static final String DEFAULT_PASSWORD_CHECK_PATTERN_STR = "^[0-9A-Za-z!@#$%^&*()_+=-]{6,32}$";
- private static final Pattern DEFAULT_PASSWORD_CHECK_PATTERN = Pattern.compile(DEFAULT_PASSWORD_CHECK_PATTERN_STR);
+ private static final Pattern DEFAULT_PASSWORD_CHECK_PATTERN =
+ Pattern.compile(DEFAULT_PASSWORD_CHECK_PATTERN_STR);
private volatile Pattern passwordCheckPattern = DEFAULT_PASSWORD_CHECK_PATTERN;
@@ -881,12 +918,6 @@ public boolean isInstanceReadOnly() {
return instanceReadOnly;
}
- private volatile boolean enable1PcOpt = true;
-
- public boolean isEnable1PcOpt() {
- return enable1PcOpt;
- }
-
// 5 min.
private volatile long minSnapshotKeepTime = 5 * 60 * 1000;
@@ -896,10 +927,59 @@ public long getMinSnapshotKeepTime() {
private volatile boolean forbidAutoCommitTrx = false;
+ private volatile Map errorCodeMapping = new HashMap<>();
+
public boolean isForbidAutoCommitTrx() {
return forbidAutoCommitTrx;
}
+ public Map getErrorCodeMapping() {
+ return errorCodeMapping;
+ }
+
+ private Map initErrorCodeMapping(String mapping) {
+ if (TStringUtil.isNotBlank(mapping)) {
+ try {
+ return JSON.parseObject(mapping, new TypeReference