in src/main/java/org/apache/paimon/trino/TrinoMetadata.java [330:414]
public ConnectorTableHandle getTableHandle(
ConnectorSession session,
SchemaTableName tableName,
Optional<ConnectorTableVersion> startVersion,
Optional<ConnectorTableVersion> endVersion) {
if (startVersion.isPresent()) {
throw new TrinoException(
NOT_SUPPORTED, "Read paimon table with start version is not supported");
}
Map<String, String> dynamicOptions = new HashMap<>();
if (endVersion.isPresent()) {
ConnectorTableVersion version = endVersion.get();
Type versionType = version.getVersionType();
switch (version.getPointerType()) {
case TEMPORAL:
{
if (!(versionType instanceof TimestampWithTimeZoneType)) {
throw new TrinoException(
NOT_SUPPORTED,
"Unsupported type for table version: "
+ versionType.getDisplayName());
}
TimestampWithTimeZoneType timeZonedVersionType =
(TimestampWithTimeZoneType) versionType;
long epochMillis =
timeZonedVersionType.isShort()
? unpackMillisUtc((long) version.getVersion())
: ((LongTimestampWithTimeZone) version.getVersion())
.getEpochMillis();
dynamicOptions.put(
CoreOptions.SCAN_TIMESTAMP_MILLIS.key(),
String.valueOf(epochMillis));
break;
}
case TARGET_ID:
{
String tagOrVersion;
if (versionType instanceof VarcharType) {
tagOrVersion =
BinaryString.fromBytes(
((Slice) version.getVersion()).getBytes())
.toString();
} else {
tagOrVersion = version.getVersion().toString();
}
// if value is not number, set tag option
boolean isNumber = StringUtils.isNumeric(tagOrVersion);
if (!isNumber) {
dynamicOptions.put(CoreOptions.SCAN_TAG_NAME.key(), tagOrVersion);
} else {
try {
catalog.initSession(session);
String path =
catalog.getTable(
new Identifier(
tableName.getSchemaName(),
tableName.getTableName()))
.options()
.get("path");
if (catalog.fileIO()
.exists(
new Path(
path
+ "/tag/"
+ TAG_PREFIX
+ tagOrVersion))) {
dynamicOptions.put(
CoreOptions.SCAN_TAG_NAME.key(), tagOrVersion);
} else {
dynamicOptions.put(
CoreOptions.SCAN_SNAPSHOT_ID.key(), tagOrVersion);
}
} catch (IOException | Catalog.TableNotExistException e) {
throw new RuntimeException(e);
}
}
break;
}
}
}
return getTableHandle(session, tableName, dynamicOptions);
}