Skip to content

Commit

Permalink
5.4.12 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldbread3 committed Jan 27, 2022
1 parent 2599de6 commit 2346eb9
Show file tree
Hide file tree
Showing 291 changed files with 6,500 additions and 2,955 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
import java.util.Set;
import java.util.TreeSet;

import static org.apache.calcite.sql.SqlKind.IN;
import static org.apache.calcite.sql.SqlKind.ROW;
import static org.apache.calcite.sql.type.SqlTypeName.BINARY;
import static org.apache.calcite.sql.type.SqlTypeName.CHAR;
import static org.apache.calcite.sql.type.SqlTypeName.DECIMAL;
Expand Down Expand Up @@ -584,6 +586,19 @@ public SqlNode toSql(RexProgram program, RexNode rex) {
case SOME:
case ALL:
if(!(rex instanceof RexSubQuery)){
/**
* `xx in row(EMPTY)` is not valid in sql, should replace it with `false`
*/
if (rex.getKind() == IN &&
((RexCall)rex).getOperands().size() == 2 &&
((RexCall)rex).getOperands().get(1) instanceof RexCall &&
((RexCall)rex).getOperands().get(1).getKind() == ROW &&
((RexCall)((RexCall)rex).getOperands().get(1)).getOperands().size() == 1 &&
((RexCall)((RexCall)rex).getOperands().get(1)).getOperands().get(0) instanceof RexDynamicParam &&
((RexDynamicParam)((RexCall)((RexCall)rex).getOperands().get(1)).getOperands().get(0)).getValue()
== RexDynamicParam.DYNAMIC_SPECIAL_VALUE.EMPTY) {
return SqlLiteral.createBoolean(false, POS);
}
final List<SqlNode> c = toSql(program, ((RexCall)rex).getOperands());
return ((RexCall) rex).getOperator().createCall(POS, c);
}
Expand Down Expand Up @@ -632,7 +647,6 @@ public SqlNode toSql(RexProgram program, RexNode rex) {
case RUNTIME_FILTER:
final List<SqlNode> c = toSql(program, ((RexCall)rex).getOperands());
return ((RexCall) rex).getOperator().createCall(POS, new SqlNodeList(c, POS));

default:
if (rex instanceof RexOver) {
return toSql(program, (RexOver) rex);
Expand Down Expand Up @@ -1158,6 +1172,7 @@ && hasNestedAggregations((LogicalAggregate) rel)) {
clauseList.appendAll(clauses);
Context newContext;
final SqlNodeList selectList = select.getSelectList();
final SqlNode selectFrom = select.getFrom();
if (selectList != null) {
newContext = new Context(selectList.size()) {
public SqlNode field(int ordinal) {
Expand All @@ -1170,15 +1185,29 @@ public SqlNode field(int ordinal) {
}

@Override public SqlNode orderField(int ordinal) {
// If the field expression is an unqualified column identifier
// and matches a different alias, use an ordinal.
// It is decided that we follow what the document of MySQL says,
// rather than what MySQL actually does:
// "MySQL resolves unqualified column or alias references in ORDER BY clauses
// by searching in the select_expr values,
// then in the columns of the tables in the FROM clause."
// For example, given
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY emp.empno
// we generate
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY 2
// "ORDER BY empno" would give incorrect result;
// "ORDER BY x" is acceptable but is not preferred.
// SELECT deptno AS empno, empno AS deptno FROM emp ORDER BY empno
// we generate physical SQL:
// SELECT deptno AS empno, empno AS deptno FROM emp ORDER BY emp.deptno
// which is the same as what MySQL does
//
// However, given
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY (empno + x)
// MySQL regards the SQL as:
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY (emp.empno + emp.empno)
// which means it searches 'from' clause first.
// we generate physical SQL:
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY (deptno + empno)
// and MySQL would regard our SQL as
// SELECT deptno AS empno, empno AS x FROM emp ORDER BY (emp.deptno + emp.empno)
final SqlNode node = field(ordinal);
// all name in 'node' comes from origin table,
// node would be simple if there is only one table in the 'from list'
if (node instanceof SqlIdentifier
&& ((SqlIdentifier) node).isSimple()) {
final String name = ((SqlIdentifier) node).getSimple();
Expand All @@ -1187,8 +1216,15 @@ public SqlNode field(int ordinal) {
final String alias =
SqlValidatorUtil.getAlias(selectItem.e, -1);
if (name.equalsIgnoreCase(alias)) {
return SqlLiteral.createExactNumeric(
Integer.toString(ordinal + 1), SqlParserPos.ZERO);
List<String> names= new ArrayList<>();
if (selectFrom.getKind() == SqlKind.AS) {
names.add(((SqlCall) selectFrom).operand(1).toString());
} else {
names.add(selectFrom.toString());
}
names.add(name);
return new SqlIdentifier(names, null,
SqlParserPos.ZERO, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ public void onMatch(RelOptRuleCall call) {
RelOptUtil.pushPastProject(filter.getCondition(), project);
RexUtil.DynamicFinder dynamicFinder = new RexUtil.DynamicFinder();
newCondition.accept(dynamicFinder);
if (dynamicFinder.getScalar().size() > 0 || dynamicFinder.getCorrelateScalar().size() > 0) {
if ((dynamicFinder.getScalar().size() > 0 &&
project.getVariablesSet() != null &&
project.getVariablesSet().size() > 0) ||
dynamicFinder.getCorrelateScalar().size() > 0) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,26 @@ public int compare(Integer rel1Idx, Integer rel2Idx) {
if ((c1 == null) || (c2 == null)) {
return -1;
}
return (c1.isLt(c2)) ? -1 : ((c1.equals(c2)) ? 0 : 1);
if (c1.isLt(c2)) {
return -1;
}
if (c2.isLt(c1)) {
return 1;
}
if (c1.equals(c2)) {
return 0;
}
double[] c1Values = new double[]{c1.getRows(), c1.getCpu(), c1.getMemory(), c1.getIo(), c1.getNet()};
double[] c2Values = new double[]{c2.getRows(), c2.getCpu(), c2.getMemory(), c2.getIo(), c2.getNet()};
for (int i = 0; i < c1Values.length; i++) {
if (c1Values[i] < c2Values[i]) {
return -1;
}
if (c1Values[i] > c2Values[i]) {
return 1;
}
}
return 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.Lists;
import com.alibaba.polardbx.common.utils.time.core.MysqlDateTime;
import com.alibaba.polardbx.common.utils.time.core.OriginalTimestamp;
import io.airlift.slice.Slice;
import org.apache.calcite.avatica.util.ByteString;
import org.apache.calcite.avatica.util.DateTimeUtils;
import org.apache.calcite.avatica.util.Spaces;
Expand Down Expand Up @@ -1652,6 +1653,8 @@ private static Object clean(Object o, RelDataType type) {
case VARCHAR:
if (o instanceof NlsString) {
return o;
}else if(o instanceof Slice){
o = ((Slice) o).toStringUtf8();
}
return new NlsString((String) o, type.getCharset().name(),
type.getCollation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class RexDynamicParam extends RexVariable {
private final int index;
private RelNode rel;
private Object value;
private boolean maxOnerow = true;
private ImmutableList<RexNode> subqueryOperands;
private SqlOperator subqueryOp;
private SqlKind subqueryKind;
Expand Down Expand Up @@ -172,6 +173,14 @@ public void setSubqueryKind(SqlKind subqueryKind) {
this.subqueryKind = subqueryKind;
}

public boolean isMaxOnerow() {
return maxOnerow;
}

public void setMaxOnerow(boolean maxOnerow) {
this.maxOnerow = maxOnerow;
}

//~ Enum
public enum DYNAMIC_SPECIAL_VALUE{
EMPTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ public interface CalciteResource {
@BaseMessage("In Global Secondary Index ''{0}'', index column ''{2}'' too long, max key length is ''{1}'' bytes")
ExInst<SqlValidatorException> gsiKeyTooLong(String name, String maxKeyLen, String colName);

@BaseMessage("Unsupported call ''{0}'' in DUPLICATE KEY UPDATE clause ")
ExInst<SqlValidatorException> unsupportedCallInDuplicateKeyUpdate(String nodeinfo);
}

//FullyQualified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.calcite.runtime;

import com.alibaba.polardbx.ssl.SslConstant;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
Expand All @@ -39,7 +41,7 @@ protected TrustAllSslSocketFactory() {
TrustManager[] trustAllCerts = {new DummyTrustManager()};
SSLSocketFactory factory = null;
try {
SSLContext sc = SSLContext.getInstance("SSL");
SSLContext sc = SSLContext.getInstance(SslConstant.PROTOCOL);
sc.init(null, trustAllCerts, new SecureRandom());
factory = sc.getSocketFactory();
} catch (Exception e) {
Expand Down Expand Up @@ -98,7 +100,8 @@ public static SSLSocketFactory createSSLSocketFactory() {
SSLSocketFactory sslsocketfactory = null;
TrustManager[] trustAllCerts = {new DummyTrustManager()};
try {
SSLContext sc = SSLContext.getInstance("SSL");

SSLContext sc = SSLContext.getInstance(SslConstant.PROTOCOL);
sc.init(null, trustAllCerts, new java.security.SecureRandom());
sslsocketfactory = sc.getSocketFactory();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class OptimizerHint extends SqlNodeList {
public final static String COMMIT_ON_SUCCESS = "COMMIT_ON_SUCCESS";
public final static String ROLLBACK_ON_FAIL = "ROLLBACK_ON_FAIL";
public final static String TARGET_AFFECT_ROW = "TARGET_AFFECT_ROW";
public final static String SQL_NO_CACHE = "SQL_NO_CACHE";

private List<String> hints = new ArrayList<>();

Expand All @@ -50,6 +51,10 @@ public List<String> getHints() {
}

public void addHint(String hint) {
if (hint.toUpperCase().contains(SQL_NO_CACHE)) {
// ignore SQL_NO_CACHE
return;
}
hints.add(hint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ public static SQLSelectOrderByItem buildIndexColumnDef(String columnName,
case "MULTIPOLYGON":
case "GEOMETRYCOLLECTION":
case "BINARY":
case "SET":
throw new UnsupportedOperationException("Invalid type for a sharding key.");
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.calcite.util.Litmus;

import java.nio.charset.Charset;
import java.util.List;

/**
* A <code>SqlDynamicParam</code> represents a dynamic parameter marker in an
Expand Down Expand Up @@ -133,6 +134,19 @@ public void unparse(
writer.print("?");
writer.setNeedWhitespace(true);
return;
}else if(realValue instanceof List){
int count=0;
for(Object tmpValue : (List)realValue){
if(count++ != 0){
writer.sep(",");
}
if(tmpValue==null){
writer.print("NULL");
continue;
}
getTypeName().createLiteral(tmpValue, pos).unparse(writer, leftPrec, rightPrec);
}
return;
}
getTypeName().createLiteral(realValue, pos).unparse(writer, leftPrec, rightPrec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.apache.calcite.sql.SqlKind.PLUS;

/**
* An operator describing a query. (Not a query itself.)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package org.apache.calcite.sql;

import java.util.LinkedList;
import java.util.List;

import com.google.common.collect.ImmutableList;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorScope;
import com.google.common.collect.ImmutableList;

import java.util.LinkedList;
import java.util.List;

/**
* @author chenmo.cm
Expand Down Expand Up @@ -87,11 +87,17 @@ public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, S
columns.add(new RelDataTypeFieldImpl("ON_FATAL_ERROR_MAX_ACTIVE",
12,
typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("ACTIVE_COUNT", 13, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("POOLING_COUNT", 14, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("ATOM", 15, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("READ_WEIGHT", 16, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("WRITE_WEIGHT", 17, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("MAX_WAIT_THREAD_COUNT",
13,
typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("ACTIVE_COUNT", 14, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("POOLING_COUNT", 15, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("ATOM", 16, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("READ_WEIGHT", 17, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("WRITE_WEIGHT", 18, typeFactory.createSqlType(SqlTypeName.VARCHAR)));
columns.add(new RelDataTypeFieldImpl("STORAGE_INST_ID",
19,
typeFactory.createSqlType(SqlTypeName.VARCHAR)));

return typeFactory.createStructType(columns);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
SqlKind.IS_DISTINCT_FROM,
30,
true,
ReturnTypes.BOOLEAN,
ReturnTypes.BIGINT_NULLABLE,
InferTypes.FIRST_KNOWN,
OperandTypes.COMPARABLE_UNORDERED_COMPARABLE_UNORDERED);

Expand All @@ -352,7 +352,7 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
SqlKind.IS_NOT_DISTINCT_FROM,
30,
true,
ReturnTypes.BOOLEAN,
ReturnTypes.BIGINT_NULLABLE,
InferTypes.FIRST_KNOWN,
OperandTypes.COMPARABLE_UNORDERED_COMPARABLE_UNORDERED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ private SqlTypeAssignmentRule(
rule.add(SqlTypeName.YEAR);
rules.add(SqlTypeName.YEAR, rule);

// BIG_BIT is assignable from ...
rule.clear();
rules.add(SqlTypeName.BIG_BIT, EnumSet.of(SqlTypeName.BIG_BIT));

// BIT is assignable from ...
rule.clear();
rule.add(SqlTypeName.BIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ public SqlLiteral createLiteral(Object o, SqlParserPos pos) {
return SqlLiteral.createBoolean(((Number) o).intValue() == 1, pos);
}
return SqlLiteral.createBoolean((Boolean) o, pos);
case FLOAT:
case TINYINT:
case TINYINT_UNSIGNED:
case SMALLINT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7496,7 +7496,7 @@ public void validateColumnListParams(
SqlFunction function,
List<RelDataType> argTypes,
List<SqlNode> operands) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("unsupported function " + function + " with arg type " + argTypes.toString());
}

private static boolean isPhysicalNavigation(SqlKind kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public static RelDataType createApplyBooleanType(RelDataTypeFactory typeFactory,
? new HashSet<String>()
: new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
addFields(leftType.getFieldList(), typeList, nameList, uniqueNameList);
typeList.add(typeFactory.createSqlType(SqlTypeName.BOOLEAN));
typeList.add(typeFactory.createSqlType(SqlTypeName.BIGINT));

String applyColumnName = APPLY_BOOLEAN;
// Ensure that name is unique from all previous field names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public CollationName getDefaultCollationName() {
return defaultCollationName;
}

public static String getDefaultCollationName(String mysqlCharset) {
CharsetName charsetName = CharsetName.of(mysqlCharset);
if (charsetName == null) {
return "";
}
return charsetName.getDefaultCollationName().name();
}

public List<CollationName> getSupportedCollationName() {
return supportedCollationName;
}
Expand Down
Loading

0 comments on commit 2346eb9

Please sign in to comment.