You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ch...@apache.org on 2020/07/28 03:03:57 UTC
[calcite] branch master updated: Remove duplicate codes and fix
typos (Auxten, Chunwei Lei)
This is an automated email from the ASF dual-hosted git repository.
chunwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 2ff1686 Remove duplicate codes and fix typos (Auxten, Chunwei Lei)
2ff1686 is described below
commit 2ff1686b286b78963b099131d1f284115c67e336
Author: Chunwei Lei <ch...@gmail.com>
AuthorDate: Fri Jul 17 15:27:47 2020 +0800
Remove duplicate codes and fix typos (Auxten, Chunwei Lei)
apache/calcite#2066
---
.../org/apache/calcite/sql/SqlBinaryOperator.java | 70 ++++++----------------
.../calcite/test/AbstractMaterializedViewTest.java | 4 +-
2 files changed, 21 insertions(+), 53 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBinaryOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlBinaryOperator.java
index 1efd2b5..d28d3e9 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlBinaryOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlBinaryOperator.java
@@ -99,31 +99,35 @@ public class SqlBinaryOperator extends SqlOperator {
SqlValidator validator,
final SqlCall call,
RelDataType type) {
- RelDataType operandType1 =
+ return convertType(validator, call, type);
+ }
+
+ private RelDataType convertType(SqlValidator validator, SqlCall call, RelDataType type) {
+ RelDataType operandType0 =
validator.getValidatedNodeType(call.operand(0));
- RelDataType operandType2 =
+ RelDataType operandType1 =
validator.getValidatedNodeType(call.operand(1));
- if (SqlTypeUtil.inCharFamily(operandType1)
- && SqlTypeUtil.inCharFamily(operandType2)) {
+ if (SqlTypeUtil.inCharFamily(operandType0)
+ && SqlTypeUtil.inCharFamily(operandType1)) {
+ Charset cs0 = operandType0.getCharset();
Charset cs1 = operandType1.getCharset();
- Charset cs2 = operandType2.getCharset();
- assert (null != cs1) && (null != cs2)
+ assert (null != cs0) && (null != cs1)
: "An implicit or explicit charset should have been set";
- if (!cs1.equals(cs2)) {
+ if (!cs0.equals(cs1)) {
throw validator.newValidationError(call,
- RESOURCE.incompatibleCharset(getName(), cs1.name(), cs2.name()));
+ RESOURCE.incompatibleCharset(getName(), cs0.name(), cs1.name()));
}
- SqlCollation col1 = operandType1.getCollation();
- SqlCollation col2 = operandType2.getCollation();
- assert (null != col1) && (null != col2)
+ SqlCollation collation0 = operandType0.getCollation();
+ SqlCollation collation1 = operandType1.getCollation();
+ assert (null != collation0) && (null != collation1)
: "An implicit or explicit collation should have been set";
- // validation will occur inside getCoercibilityDyadicOperator...
+ // Validation will occur inside getCoercibilityDyadicOperator...
SqlCollation resultCol =
SqlCollation.getCoercibilityDyadicOperator(
- col1,
- col2);
+ collation0,
+ collation1);
if (SqlTypeUtil.inCharFamily(type)) {
type =
@@ -142,43 +146,7 @@ public class SqlBinaryOperator extends SqlOperator {
SqlValidatorScope scope,
SqlCall call) {
RelDataType type = super.deriveType(validator, scope, call);
-
- RelDataType operandType1 =
- validator.getValidatedNodeType(call.operand(0));
- RelDataType operandType2 =
- validator.getValidatedNodeType(call.operand(1));
- if (SqlTypeUtil.inCharFamily(operandType1)
- && SqlTypeUtil.inCharFamily(operandType2)) {
- Charset cs1 = operandType1.getCharset();
- Charset cs2 = operandType2.getCharset();
- assert (null != cs1) && (null != cs2)
- : "An implicit or explicit charset should have been set";
- if (!cs1.equals(cs2)) {
- throw validator.newValidationError(call,
- RESOURCE.incompatibleCharset(getName(), cs1.name(), cs2.name()));
- }
-
- SqlCollation col1 = operandType1.getCollation();
- SqlCollation col2 = operandType2.getCollation();
- assert (null != col1) && (null != col2)
- : "An implicit or explicit collation should have been set";
-
- // validation will occur inside getCoercibilityDyadicOperator...
- SqlCollation resultCol =
- SqlCollation.getCoercibilityDyadicOperator(
- col1,
- col2);
-
- if (SqlTypeUtil.inCharFamily(type)) {
- type =
- validator.getTypeFactory()
- .createTypeWithCharsetAndCollation(
- type,
- type.getCharset(),
- resultCol);
- }
- }
- return type;
+ return convertType(validator, call, type);
}
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
diff --git a/core/src/test/java/org/apache/calcite/test/AbstractMaterializedViewTest.java b/core/src/test/java/org/apache/calcite/test/AbstractMaterializedViewTest.java
index fd6e35d..f9bf607 100644
--- a/core/src/test/java/org/apache/calcite/test/AbstractMaterializedViewTest.java
+++ b/core/src/test/java/org/apache/calcite/test/AbstractMaterializedViewTest.java
@@ -108,7 +108,7 @@ public abstract class AbstractMaterializedViewTest {
for (RelNode sub: substitutes) {
substituteMessages.append(RelOptUtil.toString(sub)).append("\n");
}
- throw new AssertionError("Materialized view failed to be matched by optmized results:\n"
+ throw new AssertionError("Materialized view failed to be matched by optimized results:\n"
+ substituteMessages.toString());
}
}
@@ -124,7 +124,7 @@ public abstract class AbstractMaterializedViewTest {
return;
}
final StringBuilder errMsgBuilder = new StringBuilder();
- errMsgBuilder.append("Optmization succeeds out of expectation: ");
+ errMsgBuilder.append("Optimization succeeds out of expectation: ");
for (RelNode res: results) {
errMsgBuilder.append(RelOptUtil.toString(res)).append("\n");
}