Skip to content

Instantly share code, notes, and snippets.

@jerryleooo
Created September 18, 2021 05:21
Show Gist options
  • Save jerryleooo/b2b92c2ce04a8ef78bfbb7e7ddc9a8f2 to your computer and use it in GitHub Desktop.
Save jerryleooo/b2b92c2ce04a8ef78bfbb7e7ddc9a8f2 to your computer and use it in GitHub Desktop.
jdbc changes that follows 7994
diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java
index 4fb49bf8f1..d6550f3b01 100644
--- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java
+++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java
@@ -440,6 +440,7 @@ public abstract class BaseJdbcClient
throws SQLException
{
PreparedQuery preparedQuery = prepareQuery(session, connection, table, Optional.empty(), columns, ImmutableMap.of(), Optional.of(split));
+ log.info(preparedQuery.getQuery());
return new QueryBuilder(this).prepareStatement(session, connection, preparedQuery);
}
diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
index cef672bf8f..7821a7341a 100644
--- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
+++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
@@ -61,6 +61,7 @@ import io.trino.spi.statistics.TableStatistics;
import java.sql.Types;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -81,7 +82,9 @@ import static io.trino.plugin.jdbc.JdbcMetadataSessionProperties.isJoinPushdownE
import static io.trino.plugin.jdbc.JdbcMetadataSessionProperties.isTopNPushdownEnabled;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.PERMISSION_DENIED;
+import static io.trino.spi.expression.Constant.TRUE;
import static io.trino.spi.type.BigintType.BIGINT;
+import static java.lang.Math.exp;
import static java.lang.Math.max;
import static java.util.Objects.requireNonNull;
@@ -134,6 +137,11 @@ public class DefaultJdbcMetadata
handle = flushAttributesAsQuery(session, handle);
}
+ Set<ConnectorExpression> expressions = new HashSet<>(((JdbcTableHandle)table).getExpressions());
+ if(!TRUE.equals(constraint.getExpression())) {
+ expressions.add(constraint.getExpression());
+ }
+
TupleDomain<ColumnHandle> oldDomain = handle.getConstraint();
TupleDomain<ColumnHandle> newDomain = oldDomain.intersect(constraint.getSummary());
@@ -177,9 +185,10 @@ public class DefaultJdbcMetadata
handle.getLimit(),
handle.getColumns(),
handle.getOtherReferencedTables(),
- handle.getNextSyntheticColumnId());
+ handle.getNextSyntheticColumnId(),
+ expressions);
- return Optional.of(new ConstraintApplicationResult<>(handle, remainingFilter, false));
+ return Optional.of(new ConstraintApplicationResult<>(handle, remainingFilter, false, Optional.of(constraint.getExpression())));
}
private JdbcTableHandle flushAttributesAsQuery(ConnectorSession session, JdbcTableHandle handle)
diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/JdbcTableHandle.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/JdbcTableHandle.java
index 6b0483cfcb..a847af9791 100644
--- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/JdbcTableHandle.java
+++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/JdbcTableHandle.java
@@ -21,10 +21,12 @@ import com.google.common.collect.ImmutableSet;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.connector.SchemaTableName;
+import io.trino.spi.expression.ConnectorExpression;
import io.trino.spi.predicate.TupleDomain;
import javax.annotation.Nullable;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -58,6 +60,8 @@ public final class JdbcTableHandle
private final int nextSyntheticColumnId;
+ private final Set<ConnectorExpression> expressions;
+
@Deprecated
public JdbcTableHandle(SchemaTableName schemaTableName, @Nullable String catalogName, @Nullable String schemaName, String tableName)
{
@@ -73,7 +77,20 @@ public final class JdbcTableHandle
OptionalLong.empty(),
Optional.empty(),
ImmutableSet.of(),
- 0);
+ 0,
+ Collections.EMPTY_SET);
+ }
+
+ public JdbcTableHandle(
+ JdbcRelationHandle relationHandle,
+ TupleDomain<ColumnHandle> constraint,
+ Optional<List<JdbcSortItem>> sortOrder,
+ OptionalLong limit,
+ Optional<List<JdbcColumnHandle>> columns,
+ Set<SchemaTableName> otherReferencedTables,
+ int nextSyntheticColumnId)
+ {
+ this(relationHandle, constraint, sortOrder, limit, columns, otherReferencedTables, nextSyntheticColumnId, Collections.EMPTY_SET);
}
@JsonCreator
@@ -84,7 +101,8 @@ public final class JdbcTableHandle
@JsonProperty("limit") OptionalLong limit,
@JsonProperty("columns") Optional<List<JdbcColumnHandle>> columns,
@JsonProperty("otherReferencedTables") Set<SchemaTableName> otherReferencedTables,
- @JsonProperty("nextSyntheticColumnId") int nextSyntheticColumnId)
+ @JsonProperty("nextSyntheticColumnId") int nextSyntheticColumnId,
+ @JsonProperty("expressions") Set<ConnectorExpression> expressions)
{
this.relationHandle = requireNonNull(relationHandle, "relationHandle is null");
this.constraint = requireNonNull(constraint, "constraint is null");
@@ -96,6 +114,7 @@ public final class JdbcTableHandle
this.columns = columns.map(ImmutableList::copyOf);
this.otherReferencedTables = ImmutableSet.copyOf(requireNonNull(otherReferencedTables, "otherReferencedTables is null"));
this.nextSyntheticColumnId = nextSyntheticColumnId;
+ this.expressions = expressions;
}
/**
@@ -230,6 +249,11 @@ public final class JdbcTableHandle
return nextSyntheticColumnId;
}
+ @JsonProperty
+ public Set<ConnectorExpression> getExpressions() {
+ return expressions;
+ }
+
@JsonIgnore
public boolean isSynthetic()
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment