-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support `ANALYZE` in Iceberg connector. This collects number distinct values (NDV) of selected columns.
- Loading branch information
Showing
20 changed files
with
1,331 additions
and
14 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
72 changes: 72 additions & 0 deletions
72
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergAnalyzeHandle.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,72 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.iceberg; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import io.trino.spi.connector.RetryMode; | ||
import io.trino.spi.predicate.TupleDomain; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class IcebergAnalyzeHandle | ||
extends IcebergTableHandle | ||
{ | ||
private final Set<String> analyzeColumnNames; | ||
|
||
@JsonCreator | ||
public IcebergAnalyzeHandle( | ||
@JsonProperty("schemaName") String schemaName, | ||
@JsonProperty("tableName") String tableName, | ||
@JsonProperty("snapshotId") Optional<Long> snapshotId, | ||
@JsonProperty("tableSchemaJson") String tableSchemaJson, | ||
@JsonProperty("partitionSpecJson") String partitionSpecJson, | ||
@JsonProperty("formatVersion") int formatVersion, | ||
@JsonProperty("nameMappingJson") Optional<String> nameMappingJson, | ||
@JsonProperty("tableLocation") String tableLocation, | ||
@JsonProperty("storageProperties") Map<String, String> storageProperties, | ||
@JsonProperty("analyzeColumnNames") Set<String> analyzeColumnNames) | ||
{ | ||
super( | ||
schemaName, | ||
tableName, | ||
TableType.DATA, | ||
snapshotId, | ||
tableSchemaJson, | ||
partitionSpecJson, | ||
formatVersion, | ||
TupleDomain.all(), | ||
TupleDomain.all(), | ||
ImmutableSet.of(), | ||
nameMappingJson, | ||
tableLocation, | ||
storageProperties, | ||
RetryMode.NO_RETRIES, | ||
ImmutableList.of()); | ||
|
||
this.analyzeColumnNames = ImmutableSet.copyOf(requireNonNull(analyzeColumnNames, "analyzeColumnNames is null")); | ||
} | ||
|
||
@JsonProperty | ||
public Set<String> getAnalyzeColumnNames() | ||
{ | ||
return analyzeColumnNames; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergAnalyzeProperties.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,87 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.iceberg; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.trino.spi.TrinoException; | ||
import io.trino.spi.session.PropertyMetadata; | ||
import io.trino.spi.type.ArrayType; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
import static io.trino.spi.StandardErrorCode.INVALID_ANALYZE_PROPERTY; | ||
import static io.trino.spi.type.VarcharType.VARCHAR; | ||
import static java.lang.String.format; | ||
|
||
public class IcebergAnalyzeProperties | ||
{ | ||
public static final String COLUMNS_PROPERTY = "columns"; | ||
|
||
private final List<PropertyMetadata<?>> analyzeProperties; | ||
|
||
@Inject | ||
public IcebergAnalyzeProperties() | ||
{ | ||
analyzeProperties = ImmutableList.<PropertyMetadata<?>>builder() | ||
.add(new PropertyMetadata<>( | ||
COLUMNS_PROPERTY, | ||
"Columns to be analyzed", | ||
new ArrayType(VARCHAR), | ||
Set.class, | ||
null, | ||
false, | ||
IcebergAnalyzeProperties::decodeColumnNames, | ||
value -> value)) | ||
.build(); | ||
} | ||
|
||
public List<PropertyMetadata<?>> getAnalyzeProperties() | ||
{ | ||
return analyzeProperties; | ||
} | ||
|
||
public static Optional<Set<String>> getColumnNames(Map<String, Object> properties) | ||
{ | ||
@SuppressWarnings("unchecked") | ||
Set<String> columns = (Set<String>) properties.get(COLUMNS_PROPERTY); | ||
return Optional.ofNullable(columns); | ||
} | ||
|
||
private static Set<String> decodeColumnNames(Object object) | ||
{ | ||
if (object == null) { | ||
return null; | ||
} | ||
|
||
Collection<?> columns = ((Collection<?>) object); | ||
return columns.stream() | ||
.peek(property -> throwIfNull(property, "columns")) | ||
.map(String.class::cast) | ||
.collect(toImmutableSet()); | ||
} | ||
|
||
private static void throwIfNull(Object object, String propertyName) | ||
{ | ||
if (object == null) { | ||
throw new TrinoException(INVALID_ANALYZE_PROPERTY, format("Invalid null value in analyze %s property", propertyName)); | ||
} | ||
} | ||
} |
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.