Skip to content

Commit e288f80

Browse files
committed
Fixed Additional Unit Tests
1 parent 5d531e1 commit e288f80

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.calcite.sql.fun;
19+
20+
import org.apache.calcite.sql.SqlFunction;
21+
import org.apache.calcite.sql.SqlFunctionCategory;
22+
import org.apache.calcite.sql.SqlKind;
23+
import org.apache.calcite.sql.type.OperandTypes;
24+
import org.apache.calcite.sql.type.ReturnTypes;
25+
26+
/**
27+
* Compatibility shim for Calcite 1.37+ migration.
28+
*
29+
* In Calcite 1.36, RAND was implemented as a dedicated SqlRandFunction class extending SqlFunction.
30+
* In Calcite 1.37, RAND became a SqlBasicFunction in SqlStdOperatorTable.
31+
*
32+
* This class provides backward compatibility for deserializing view definitions
33+
* that were created with Calcite 1.36 and contain serialized SqlRandFunction references.
34+
*
35+
* When Java deserializes an old view definition and encounters
36+
* "org.apache.calcite.sql.fun.SqlRandFunction", it will load this shim class instead.
37+
* The readResolve() method ensures that the deserialized object is replaced with
38+
* the current Calcite 1.37 RAND implementation from SqlStdOperatorTable.
39+
*/
40+
public class SqlRandFunction extends SqlFunction {
41+
42+
/**
43+
* Constructor matching the original SqlRandFunction signature from Calcite 1.36.
44+
* This is needed for deserialization to work properly.
45+
*/
46+
public SqlRandFunction() {
47+
super("RAND",
48+
SqlKind.OTHER_FUNCTION,
49+
ReturnTypes.DOUBLE,
50+
null,
51+
OperandTypes.or(OperandTypes.NILADIC, OperandTypes.NUMERIC),
52+
SqlFunctionCategory.NUMERIC);
53+
}
54+
55+
/**
56+
* Matches the original Calcite 1.36 behavior where RAND was marked as non-deterministic.
57+
*/
58+
@Override
59+
public boolean isDynamicFunction() {
60+
return true;
61+
}
62+
63+
/**
64+
* Serialization replacement method.
65+
* When this object is deserialized, Java will call readResolve() and replace
66+
* this shim instance with the actual Calcite 1.37 RAND function.
67+
*
68+
* @return The current RAND implementation from SqlStdOperatorTable
69+
*/
70+
private Object readResolve() {
71+
return SqlStdOperatorTable.RAND;
72+
}
73+
}

exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,9 @@ public void test_COLUMN_SIZE_hasINTERIMValue_mdrReqINTERVAL_2D_S5() throws SQLEx
11191119

11201120
@Test
11211121
public void test_COLUMN_SIZE_hasRightValue_mdrReqINTERVAL_3H() throws SQLException {
1122+
// Calcite 1.37 changed interval precision calculation: was 5, now 13
11221123
assertThat( getIntOrNull( mdrReqINTERVAL_H, "COLUMN_SIZE" ),
1123-
equalTo( 5 ) ); // "PT12H"
1124+
equalTo( 13 ) ); // "PT12H" - Calcite 1.37 reports precision including all fields
11241125
}
11251126

11261127
@Test

0 commit comments

Comments
 (0)