Skip to content

Commit

Permalink
[CALCITE-6325] Modify to MYSQL unified style
Browse files Browse the repository at this point in the history
  • Loading branch information
caicancai committed Mar 25, 2024
1 parent adcbe2e commit ee2ed68
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOG2;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_AND;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_OR;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOG_MYSQL_SPARK;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOG_MYSQL;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LPAD;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.MAP;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.MAP_CONCAT;
Expand Down Expand Up @@ -649,10 +649,10 @@ Builder populate() {
map.put(LOG, logImplementor);
map.put(LOG10, logImplementor);

LogImplementor logMysqlSparkImplementor =
new LogImplementor(BuiltInMethod.LOG_MYSQL_SPARK.method);
map.put(LOG_MYSQL_SPARK, logMysqlSparkImplementor);
map.put(LOG2, logMysqlSparkImplementor);
LogImplementor logMysqlImplementor =
new LogImplementor(BuiltInMethod.LOG_MYSQL.method);
map.put(LOG_MYSQL, logMysqlImplementor);
map.put(LOG2, logMysqlImplementor);

defineReflective(RAND, BuiltInMethod.RAND.method,
BuiltInMethod.RAND_SEED.method);
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2790,26 +2790,26 @@ public static double log(BigDecimal d0, BigDecimal d1) {

/** SQL {@code LOG(number, number2)} function applied to double values.
* but return null when number2 is 0. */
public static @Nullable Double logMysqlSpark(double number, double number2) {
public static @Nullable Double logMysql(double number, double number2) {
return (number <= 0) ? null : log(number, number2);
}

/** SQL {@code LOG(number, number2)} function applied to double and BigDecimal values.
* but return null when number2 is 0. */
public static @Nullable Double logMysqlSpark(double number, BigDecimal number2) {
return logMysqlSpark(number, number2.doubleValue());
public static @Nullable Double logMysql(double number, BigDecimal number2) {
return logMysql(number, number2.doubleValue());
}

/** SQL {@code LOG(number, number2)} function applied to BigDecimal and double values.
* but return null when number2 is 0. */
public static @Nullable Double logMysqlSpark(BigDecimal number, double number2) {
return logMysqlSpark(number.doubleValue(), number2);
public static @Nullable Double logMysql(BigDecimal number, double number2) {
return logMysql(number.doubleValue(), number2);
}

/** SQL {@code LOG(number, number2)} function applied to double values.
* but return null when number2 is 0. */
public static @Nullable Double logMysqlSpark(BigDecimal number, BigDecimal number2) {
return logMysqlSpark(number.doubleValue(), number2.doubleValue());
public static @Nullable Double logMysql(BigDecimal number, BigDecimal number2) {
return logMysql(number.doubleValue(), number2.doubleValue());
}

// MOD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding

/** The "LOG(numeric1, numeric2)" function. Returns the base numeric1 logarithm of numeric. */
@LibraryOperator(libraries = {MYSQL, SPARK})
public static final SqlFunction LOG_MYSQL_SPARK =
public static final SqlFunction LOG_MYSQL =
SqlBasicFunction.create("LOG",
ReturnTypes.DOUBLE_FORCE_NULLABLE,
OperandTypes.NUMERIC_OPTIONAL_NUMERIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public enum BuiltInMethod {
SAFE_MULTIPLY(SqlFunctions.class, "safeMultiply", double.class, double.class),
SAFE_SUBTRACT(SqlFunctions.class, "safeSubtract", double.class, double.class),
LOG(SqlFunctions.class, "log", long.class, long.class),
LOG_MYSQL_SPARK(SqlFunctions.class, "logMysqlSpark", long.class, long.class),
LOG_MYSQL(SqlFunctions.class, "logMysql", long.class, long.class),
SEC(SqlFunctions.class, "sec", double.class),
SECH(SqlFunctions.class, "sech", double.class),
SIGN(SqlFunctions.class, "sign", long.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6341,11 +6341,11 @@ void checkRegexpExtract(SqlOperatorFixture f0, FunctionAlias functionAlias) {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6325">[CALCITE-6325]
* Add LOG function (enabled in MYSQL library)</a>. */
@Test void testLogMysqlSparkFunc() {
@Test void testLogMysqlFunc() {
final SqlOperatorFixture f0 = fixture();
f0.checkFails("^log(100, 10)^",
"No match found for function signature LOG\\(<NUMERIC>, <NUMERIC>\\)", false);
f0.setFor(SqlLibraryOperators.LOG_MYSQL_SPARK);
f0.setFor(SqlLibraryOperators.LOG_MYSQL);
final Consumer<SqlOperatorFixture> consumer = f -> {
f.checkScalarApprox("log(10, 10)", "DOUBLE",
isWithin(1.0, 0.000001));
Expand Down

0 comments on commit ee2ed68

Please sign in to comment.