-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the Abs, Ceil and Floor methods now return proper types (#3948)
BREAKING CHANGE: abs, ceil and floor will now return types aligned with other databases systems (i.e. the same type as the input). Previously these udfs would always return Double.
- Loading branch information
Showing
20 changed files
with
171 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ksql-engine/src/main/java/io/confluent/ksql/function/udf/math/Ceil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.function.udf.math; | ||
|
||
import io.confluent.ksql.function.udf.Udf; | ||
import io.confluent.ksql.function.udf.UdfDescription; | ||
import io.confluent.ksql.function.udf.UdfParameter; | ||
import io.confluent.ksql.function.udf.UdfSchemaProvider; | ||
import io.confluent.ksql.schema.ksql.SqlBaseType; | ||
import io.confluent.ksql.schema.ksql.types.SqlType; | ||
import io.confluent.ksql.util.KsqlException; | ||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.util.List; | ||
|
||
@UdfDescription(name = "Ceil", description = Ceil.DESCRIPTION) | ||
public class Ceil { | ||
|
||
static final String DESCRIPTION = "Returns the smallest integer greater than or equal to the " | ||
+ "specified numeric expression."; | ||
|
||
@Udf | ||
public Integer ceil(@UdfParameter final Integer val) { | ||
return val; | ||
} | ||
|
||
@Udf | ||
public Long ceil(@UdfParameter final Long val) { | ||
return val; | ||
} | ||
|
||
@Udf | ||
public Double ceil(@UdfParameter final Double val) { | ||
return (val == null) ? null : Math.ceil(val); | ||
} | ||
|
||
@Udf(schemaProvider = "ceilDecimalProvider") | ||
public BigDecimal ceil(@UdfParameter final BigDecimal val) { | ||
return val == null | ||
? null | ||
: val.setScale(0, RoundingMode.CEILING).setScale(val.scale(), RoundingMode.UNNECESSARY); | ||
} | ||
|
||
@UdfSchemaProvider | ||
public SqlType ceilDecimalProvider(final List<SqlType> params) { | ||
final SqlType s = params.get(0); | ||
if (s.baseType() != SqlBaseType.DECIMAL) { | ||
throw new KsqlException("The schema provider method for Ceil expects a BigDecimal parameter" | ||
+ "type"); | ||
} | ||
return s; | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
ksql-engine/src/main/java/io/confluent/ksql/function/udf/math/CeilKudf.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.