Skip to content

Commit 6d52791

Browse files
committed
[CALCITE-7351] Make getMaxNumericScale() and getMaxNumericPrecision() final
Replace them with getMaxPrecision(SqlTypeName.DECIMAL) and getMaxScale(SqlTypeName.DECIMAL), respectively.
1 parent 92cfb30 commit 6d52791

File tree

10 files changed

+27
-104
lines changed

10 files changed

+27
-104
lines changed

core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,53 +96,29 @@ public interface RelDataTypeSystem {
9696
*
9797
* @deprecated Replaced by {@link #getMaxScale}(DECIMAL).
9898
*
99-
* <p>From Calcite release 1.38 onwards, instead of calling this method, you
100-
* should call {@code getMaxScale(DECIMAL)}.
99+
* <p>Instead of calling this method, you should call
100+
* {@code getMaxScale(DECIMAL)}.
101101
*
102-
* <p>In Calcite release 1.38, if you wish to change the maximum
103-
* scale of {@link SqlTypeName#DECIMAL} values, you should do two things:
104-
*
105-
* <ul>
106-
* <li>Override the {@link #getMaxScale(SqlTypeName)} method,
107-
* changing its behavior for {@code DECIMAL};
108-
* <li>Make sure that the implementation of your
109-
* {@code #getMaxNumericScale} method calls
110-
* {@code getMaxScale(DECIMAL)}.
111-
* </ul>
112-
*
113-
* <p>In Calcite release 1.39, Calcite will cease calling this method,
114-
* and will remove the override of the method in
115-
* {@link RelDataTypeSystemImpl}. You should remove all calls to
116-
* and overrides of this method. */
117-
@Deprecated // calcite will cease calling in 1.39, and removed before 2.0
102+
* <p>If you wish to change the maximum scale of {@link SqlTypeName#DECIMAL}
103+
* values, override the {@link #getMaxScale(SqlTypeName)} method,
104+
* changing its behavior for {@code DECIMAL}. */
105+
@Deprecated // to be removed before 2.0
118106
default int getMaxNumericScale() {
119-
return 19;
107+
return getMaxScale(SqlTypeName.DECIMAL);
120108
}
121109

122110
/** Returns the maximum precision of a NUMERIC or DECIMAL type.
123111
* Default value is 19.
124112
*
125-
* @deprecated Replaced by {@link #getMaxScale}(DECIMAL).
113+
* @deprecated Replaced by {@link #getMaxPrecision}(DECIMAL).
126114
*
127-
* <p>From Calcite release 1.38 onwards, instead of calling this method, you
128-
* should call {@code getMaxPrecision(DECIMAL)}.
129-
*
130-
* <p>In Calcite release 1.38, if you wish to change the maximum
131-
* precision of {@link SqlTypeName#DECIMAL} values, you should do two things:
132-
*
133-
* <ul>
134-
* <li>Override the {@link #getMaxPrecision(SqlTypeName)} method,
135-
* changing its behavior for {@code DECIMAL};
136-
* <li>Make sure that the implementation of your
137-
* {@code #getMaxNumericPrecision} method calls
138-
* {@code getMaxPrecision(DECIMAL)}.
139-
* </ul>
115+
* <p>Instead of calling this method, you should call
116+
* {@code getMaxPrecision(DECIMAL)}.
140117
*
141-
* <p>In Calcite release 1.39, Calcite will cease calling this method,
142-
* and will remove the override of the method in
143-
* {@link RelDataTypeSystemImpl}. You should remove all calls to
144-
* and overrides of this method. */
145-
@Deprecated // calcite will cease calling in 1.39, and removed before 2.0
118+
* <p>If you wish to change the maximum precision of {@link SqlTypeName#DECIMAL}
119+
* values, override the {@link #getMaxPrecision(SqlTypeName)} method,
120+
* changing its behavior for {@code DECIMAL}. */
121+
@Deprecated // to be removed before 2.0
146122
default int getMaxNumericPrecision() {
147123
return getMaxPrecision(SqlTypeName.DECIMAL);
148124
}

core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystemImpl.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public abstract class RelDataTypeSystemImpl implements RelDataTypeSystem {
4646
@Override public int getMaxScale(SqlTypeName typeName) {
4747
switch (typeName) {
4848
case DECIMAL:
49-
// from 1.39, this will be 'return 19;'
50-
return getMaxNumericScale();
49+
return 19;
5150
case INTERVAL_YEAR:
5251
case INTERVAL_YEAR_MONTH:
5352
case INTERVAL_MONTH:
@@ -107,8 +106,7 @@ public abstract class RelDataTypeSystemImpl implements RelDataTypeSystem {
107106
case VARBINARY:
108107
return RelDataType.PRECISION_NOT_SPECIFIED;
109108
case DECIMAL:
110-
// from 1.39, this will be 'return getMaxPrecision(typeName);'
111-
return getMaxNumericPrecision();
109+
return getMaxPrecision(typeName);
112110
case INTERVAL_YEAR:
113111
case INTERVAL_YEAR_MONTH:
114112
case INTERVAL_MONTH:
@@ -187,8 +185,7 @@ public abstract class RelDataTypeSystemImpl implements RelDataTypeSystem {
187185
@Override public int getMaxPrecision(SqlTypeName typeName) {
188186
switch (typeName) {
189187
case DECIMAL:
190-
// from 1.39, this will be 'return 19;'
191-
return getMaxNumericPrecision();
188+
return 19;
192189
case VARCHAR:
193190
case CHAR:
194191
return 65536;
@@ -262,13 +259,13 @@ public abstract class RelDataTypeSystemImpl implements RelDataTypeSystem {
262259
}
263260

264261
@SuppressWarnings("deprecation")
265-
@Override public int getMaxNumericScale() {
266-
return 19;
262+
@Override public final int getMaxNumericScale() {
263+
return getMaxScale(SqlTypeName.DECIMAL);
267264
}
268265

269266
@SuppressWarnings("deprecation")
270-
@Override public int getMaxNumericPrecision() {
271-
return 19;
267+
@Override public final int getMaxNumericPrecision() {
268+
return getMaxPrecision(SqlTypeName.DECIMAL);
272269
}
273270

274271
@Override public RoundingMode roundingMode() {

core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ public class ClickHouseSqlDialect extends SqlDialect {
6969
return super.getMaxScale(typeName);
7070
}
7171
}
72-
73-
@Override public int getMaxNumericScale() {
74-
return getMaxScale(SqlTypeName.DECIMAL);
75-
}
7672
};
7773

7874
public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT

core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public class DuckDBSqlDialect extends SqlDialect {
5454
return super.getMaxScale(typeName);
5555
}
5656
}
57-
58-
@Override public int getMaxNumericScale() {
59-
return getMaxScale(SqlTypeName.DECIMAL);
60-
}
6157
};
6258

6359
public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT

core/src/main/java/org/apache/calcite/sql/dialect/PhoenixSqlDialect.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ public class PhoenixSqlDialect extends SqlDialect {
5555
return super.getMaxScale(typeName);
5656
}
5757
}
58-
59-
@Override public int getMaxNumericScale() {
60-
return getMaxScale(SqlTypeName.DECIMAL);
61-
}
6258
};
6359

6460
public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT

core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public class PrestoSqlDialect extends SqlDialect {
8484
return super.getMaxScale(typeName);
8585
}
8686
}
87-
88-
@Override public int getMaxNumericScale() {
89-
return getMaxScale(SqlTypeName.DECIMAL);
90-
}
9187
};
9288

9389
public static final Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT

core/src/main/java/org/apache/calcite/sql/dialect/RedshiftSqlDialect.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public class RedshiftSqlDialect extends SqlDialect {
4949
}
5050
}
5151

52-
@Override public int getMaxNumericPrecision() {
53-
return getMaxPrecision(SqlTypeName.DECIMAL);
54-
}
55-
5652
@Override public int getMaxScale(SqlTypeName typeName) {
5753
switch (typeName) {
5854
case DECIMAL:
@@ -61,10 +57,6 @@ public class RedshiftSqlDialect extends SqlDialect {
6157
return super.getMaxScale(typeName);
6258
}
6359
}
64-
65-
@Override public int getMaxNumericScale() {
66-
return getMaxScale(SqlTypeName.DECIMAL);
67-
}
6860
};
6961

7062
public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT

core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11380,10 +11380,6 @@ Sql withPostgresqlModifiedDecimalTypeSystem() {
1138011380
new PostgresqlSqlDialect(PostgresqlSqlDialect.DEFAULT_CONTEXT
1138111381
.withDataTypeSystem(
1138211382
new RelDataTypeSystemImpl() {
11383-
@Override public int getMaxNumericScale() {
11384-
return getMaxScale(SqlTypeName.DECIMAL);
11385-
}
11386-
1138711383
@Override public int getMaxScale(SqlTypeName typeName) {
1138811384
switch (typeName) {
1138911385
case DECIMAL:
@@ -11393,10 +11389,6 @@ Sql withPostgresqlModifiedDecimalTypeSystem() {
1139311389
}
1139411390
}
1139511391

11396-
@Override public int getMaxNumericPrecision() {
11397-
return getMaxPrecision(SqlTypeName.DECIMAL);
11398-
}
11399-
1140011392
@Override public int getMaxPrecision(SqlTypeName typeName) {
1140111393
switch (typeName) {
1140211394
case DECIMAL:

core/src/test/java/org/apache/calcite/sql/type/RelDataTypeSystemTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ private static final class CustomTypeSystem extends RelDataTypeSystemImpl {
127127
return type1;
128128
}
129129

130-
@Override public int getMaxNumericPrecision() {
131-
return 38;
132-
}
133-
134130
@Override public int getMaxPrecision(SqlTypeName typeName) {
135-
if (typeName == SqlTypeName.TIMESTAMP) {
131+
switch (typeName) {
132+
case DECIMAL:
133+
return 38;
134+
case TIMESTAMP:
136135
return CUSTOM_MAX_TIMESTAMP_PRECISION;
136+
default:
137+
return super.getMaxPrecision(typeName);
137138
}
138-
return super.getMaxPrecision(typeName);
139139
}
140140
}
141141

@@ -209,10 +209,6 @@ static class Fixture extends SqlTypeFixture {
209209
* Custom type system class that overrides the default max precision and max scale.
210210
*/
211211
final class CustomTypeSystem extends RelDataTypeSystemImpl {
212-
@Override public int getMaxNumericPrecision() {
213-
return getMaxPrecision(SqlTypeName.DECIMAL);
214-
}
215-
216212
@Override public int getMaxPrecision(SqlTypeName typeName) {
217213
switch (typeName) {
218214
case DECIMAL:
@@ -222,10 +218,6 @@ final class CustomTypeSystem extends RelDataTypeSystemImpl {
222218
}
223219
}
224220

225-
@Override public int getMaxNumericScale() {
226-
return getMaxScale(SqlTypeName.DECIMAL);
227-
}
228-
229221
@Override public int getMaxScale(SqlTypeName typeName) {
230222
switch (typeName) {
231223
case DECIMAL:

core/src/test/java/org/apache/calcite/tools/FrameworksTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,6 @@ public static class HiveLikeTypeSystem extends RelDataTypeSystemImpl {
530530

531531
private HiveLikeTypeSystem() {}
532532

533-
@Override public int getMaxNumericPrecision() {
534-
assert super.getMaxNumericPrecision() == 19;
535-
return getMaxPrecision(SqlTypeName.DECIMAL);
536-
}
537-
538533
@Override public int getMaxPrecision(SqlTypeName typeName) {
539534
switch (typeName) {
540535
case DECIMAL:
@@ -550,11 +545,6 @@ private HiveLikeTypeSystem() {}
550545
public static class HiveLikeTypeSystem2 extends RelDataTypeSystemImpl {
551546
public HiveLikeTypeSystem2() {}
552547

553-
@Override public int getMaxNumericPrecision() {
554-
assert super.getMaxNumericPrecision() == 19;
555-
return getMaxPrecision(SqlTypeName.DECIMAL);
556-
}
557-
558548
@Override public int getMaxPrecision(SqlTypeName typeName) {
559549
switch (typeName) {
560550
case DECIMAL:

0 commit comments

Comments
 (0)