Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
SQL: Create millisecond precision timestamp literals. (#12407)
* SQL: Create millisecond precision timestamp literals. Fixes a bug where implicit casts of strings to timestamps would use seconds precision rather than milliseconds. The new test case testCountStarWithBetweenTimeFilterUsingMillisecondsInStringLiterals exercises this. * Update sql/src/main/java/org/apache/druid/sql/calcite/planner/Calcites.java Co-authored-by: Frank Chen <frankchen@apache.org> * Correct precision handling. - Set default precision to 3 (millis) for things involving timestamps. - Respect precision specified in types when available. * Silence, checkstyle. Co-authored-by: Frank Chen <frankchen@apache.org>
- Loading branch information
1 parent
72d15ab
commit 2e42d04038a27863e0c8f3bb7704c1a362ede27e
Showing
8 changed files
with
225 additions
and
32 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
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.sql.calcite.planner; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.SqlOperatorBinding; | ||
import org.apache.calcite.sql.fun.SqlAbstractTimeFunction; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
/** | ||
* Used for functions like CURRENT_TIMESTAMP and LOCALTIME. | ||
* | ||
* Similar to {@link SqlAbstractTimeFunction}, but default precision is | ||
* {@link DruidTypeSystem#DEFAULT_TIMESTAMP_PRECISION} instead of 0. | ||
*/ | ||
public class CurrentTimestampSqlFunction extends SqlAbstractTimeFunction | ||
{ | ||
private final SqlTypeName typeName; | ||
|
||
public CurrentTimestampSqlFunction(final String name, final SqlTypeName typeName) | ||
{ | ||
super(name, typeName); | ||
this.typeName = typeName; | ||
} | ||
|
||
@Override | ||
public RelDataType inferReturnType(SqlOperatorBinding opBinding) | ||
{ | ||
if (opBinding.getOperandCount() == 0) { | ||
return opBinding.getTypeFactory().createSqlType(typeName, DruidTypeSystem.DEFAULT_TIMESTAMP_PRECISION); | ||
} else { | ||
return super.inferReturnType(opBinding); | ||
} | ||
} | ||
} |
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.