New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-12253][table-common] Setup a class hierarchy for the new logical type system #8335
Closed
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a6a8f2a
[FLINK-12253][table-common] Introduce logical type skeleton
twalthr 143887c
[FLINK-12253][table-common] Add a CHAR type
twalthr d2fd35f
[FLINK-12253][table-common] Add a VARCHAR type
twalthr 2bfc47d
[FLINK-12253][table-common] Add a BOOLEAN type
twalthr 063398d
[FLINK-12253][table-common] Add a BINARY type
twalthr c0652a4
[FLINK-12253][table-common] Add a VARBINARY type
twalthr db0e8cb
[FLINK-12253][table-common] Add a DECIMAL type
twalthr 52229e1
[FLINK-12253][table-common] Add a TINYINT type
twalthr a6fe3ff
[FLINK-12253][table-common] Add a SMALLINT type
twalthr 908aa48
[FLINK-12253][table-common] Add a INT type
twalthr 08fa733
[FLINK-12253][table-common] Add a BIGINT type
twalthr 6fb6b8e
[FLINK-12253][table-common] Add a FLOAT type
twalthr 6e0cffd
[FLINK-12253][table-common] Add a DOUBLE type
twalthr ea6a13c
[FLINK-12253][table-common] Add a DATE type
twalthr 06ccb79
[FLINK-12253][table-common] Add a TIME type
twalthr 73e2dee
[FLINK-12253][table-common] Add a TIMESTAMP type
twalthr 00ea5ef
[FLINK-12253][table-common] Add a TIMESTAMP WITH TIME ZONE type
twalthr aabaf5a
[FLINK-12253][table-common] Add a TIMESTAMP WITH LOCAL TIME ZONE type
twalthr 13580d4
[FLINK-12253][table-common] Add an INTERVAL YEAR TO MONTH type
twalthr efb19a7
[FLINK-12253][table-common] Add an INTERVAL DAY TO SECOND type
twalthr c4ac5ad
[FLINK-12253][table-common] Add an ARRAY type
twalthr 65a71d3
[FLINK-12253][table-common] Add a MULTISET type
twalthr b266f0e
[FLINK-12253][table-common] Add a MAP type
twalthr 7400873
[FLINK-12253][table-common] Add a ROW type
twalthr df20555
[FLINK-12253][table-common] Add user-defined types
twalthr 2fdf042
[FLINK-12253][table-common] Add a NULL type
twalthr 6da683b
[FLINK-12253][table-common] Add an ANY type
twalthr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
144 changes: 144 additions & 0 deletions
144
...table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/TimeType.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,144 @@ | ||
/* | ||
* 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.flink.table.types.logical; | ||
|
||
import org.apache.flink.annotation.PublicEvolving; | ||
import org.apache.flink.table.api.ValidationException; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* Logical type of a time WITHOUT timezone consisting of {@code hour:minute:second[.fractional]} with up | ||
* to nanosecond precision and values ranging from {@code 00:00:00.000000000} to | ||
* {@code 23:59:59.999999999}. Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are | ||
* not supported as the semantics are closer to {@link java.time.LocalTime}. | ||
* | ||
* <p>The serialized string representation is {@code TIME(p)} where {@code p} is the number of digits | ||
* of fractional seconds (=precision). {@code p} must have a value between 0 and 9 (both inclusive). | ||
* If no precision is specified, {@code p} is equal to 0. | ||
* | ||
* <p>A conversion from and to {@code int} describes the number of milliseconds of the day. A | ||
* conversion from and to {@code long} describes the number of nanoseconds of the day. | ||
*/ | ||
@PublicEvolving | ||
public final class TimeType extends LogicalType { | ||
|
||
private static final int MIN_PRECISION = 0; | ||
|
||
private static final int MAX_PRECISION = 9; | ||
|
||
private static final int DEFAULT_PRECISION = 0; | ||
|
||
private static final String DEFAULT_FORMAT = "TIME(%d)"; | ||
|
||
private static final Set<String> NULL_OUTPUT_CONVERSION = conversionSet( | ||
java.sql.Time.class.getName(), | ||
java.time.LocalTime.class.getName()); | ||
|
||
private static final Set<String> NOT_NULL_INPUT_OUTPUT_CONVERSION = conversionSet( | ||
java.sql.Time.class.getName(), | ||
java.time.LocalTime.class.getName(), | ||
int.class.getName(), | ||
long.class.getName()); | ||
|
||
private static final Class<?> DEFAULT_CONVERSION = java.time.LocalTime.class; | ||
|
||
private final int precision; | ||
|
||
public TimeType(boolean isNullable, int precision) { | ||
super(isNullable, LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE); | ||
if (precision < MIN_PRECISION || precision > MAX_PRECISION) { | ||
throw new ValidationException( | ||
String.format( | ||
"Time precision must be between %d and %d (both inclusive).", | ||
MIN_PRECISION, | ||
MAX_PRECISION)); | ||
} | ||
this.precision = precision; | ||
} | ||
|
||
public TimeType(int precision) { | ||
this(true, precision); | ||
} | ||
|
||
public TimeType() { | ||
this(DEFAULT_PRECISION); | ||
} | ||
|
||
@Override | ||
public LogicalType copy(boolean isNullable) { | ||
return new TimeType(isNullable, precision); | ||
} | ||
|
||
@Override | ||
public String asSerializableString() { | ||
return withNullability(DEFAULT_FORMAT, precision); | ||
} | ||
|
||
@Override | ||
public boolean supportsInputConversion(Class<?> clazz) { | ||
return NOT_NULL_INPUT_OUTPUT_CONVERSION.contains(clazz.getName()); | ||
} | ||
|
||
@Override | ||
public boolean supportsOutputConversion(Class<?> clazz) { | ||
if (isNullable()) { | ||
return NULL_OUTPUT_CONVERSION.contains(clazz.getName()); | ||
} | ||
return NOT_NULL_INPUT_OUTPUT_CONVERSION.contains(clazz.getName()); | ||
} | ||
|
||
@Override | ||
public Class<?> getDefaultOutputConversion() { | ||
return DEFAULT_CONVERSION; | ||
} | ||
|
||
@Override | ||
public List<LogicalType> getChildren() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public <R> R accept(LogicalTypeVisitor<R> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
TimeType timeType = (TimeType) o; | ||
return precision == timeType.precision; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), precision); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can
Time
have a timezone in general? Doesn't timezone imply there has to be date component?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL standard also defines a
TIME WITH TIME ZONE
. I will explicitly mention that we won't support that. Java does also not provide a time class for such a type.