Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
*/
package io.trino.plugin.faker;

import com.google.common.collect.ImmutableMap;
import io.trino.spi.connector.ColumnMetadata;
import io.trino.spi.type.Type;

import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -57,4 +59,16 @@ public ColumnInfo withComment(Optional<String> comment)
.setComment(comment)
.build());
}

public ColumnInfo withHandle(FakerColumnHandle handle)
{
return new ColumnInfo(handle, metadata);
}

public ColumnInfo withProperties(Map<String, Object> properties)
{
return new ColumnInfo(handle, ColumnMetadata.builderFrom(metadata)
.setProperties(ImmutableMap.copyOf(properties))
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@ private static List<String> strings(Collection<?> values)
.map(String.class::cast)
.collect(toImmutableList());
}

public FakerColumnHandle withNullProbability(double nullProbability)
{
return new FakerColumnHandle(columnIndex, name, type, nullProbability, generator, domain, step);
}

public FakerColumnHandle withDomain(Domain domain)
{
return new FakerColumnHandle(columnIndex, name, type, nullProbability, generator, domain, step);
}

public FakerColumnHandle withStep(ValueSet step)
{
return new FakerColumnHandle(columnIndex, name, type, nullProbability, generator, domain, step);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class FakerConfig
private double nullProbability = 0.5;
private long defaultLimit = 1000L;
private Locale locale = Locale.ENGLISH;
private boolean sequenceDetectionEnabled = true;
private boolean dictionaryDetectionEnabled = true;

@Max(1)
@Min(0)
Expand Down Expand Up @@ -68,4 +70,36 @@ public FakerConfig setLocale(String value)
this.locale = new Locale.Builder().setLanguageTag(value).build();
return this;
}

public boolean isSequenceDetectionEnabled()
{
return sequenceDetectionEnabled;
}

@Config("faker.sequence-detection-enabled")
@ConfigDescription(
"""
If true, when creating a table using existing data, columns with the number of distinct values close to
the number of rows will be treated as sequences""")
public FakerConfig setSequenceDetectionEnabled(boolean value)
{
this.sequenceDetectionEnabled = value;
return this;
}

public boolean isDictionaryDetectionEnabled()
{
return dictionaryDetectionEnabled;
}

@Config("faker.dictionary-detection-enabled")
@ConfigDescription(
"""
If true, when creating a table using existing data, columns with a low number of distinct values
will have the allowed_values column property populated with random values""")
public FakerConfig setDictionaryDetectionEnabled(boolean value)
{
this.dictionaryDetectionEnabled = value;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static io.trino.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY;
import static io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY;
import static io.trino.spi.connector.ConnectorCapabilities.NOT_NULL_COLUMN_CONSTRAINT;
import static io.trino.spi.session.PropertyMetadata.booleanProperty;
import static io.trino.spi.session.PropertyMetadata.doubleProperty;
import static io.trino.spi.session.PropertyMetadata.longProperty;
import static io.trino.spi.session.PropertyMetadata.stringProperty;
Expand Down Expand Up @@ -125,6 +126,20 @@ public List<PropertyMetadata<?>> getSchemaProperties()
"Default limit of rows returned from any table in this schema, if not specified in the query",
null,
defaultLimit -> checkProperty(1 <= defaultLimit, INVALID_SCHEMA_PROPERTY, "default_limit value must be equal or greater than 1"),
false),
booleanProperty(
SchemaInfo.SEQUENCE_DETECTION_ENABLED,
"""
If true, when creating a table using existing data, columns with the number of distinct values close to
the number of rows will be treated as sequences""",
null,
false),
booleanProperty(
SchemaInfo.DICTIONARY_DETECTION_ENABLED,
"""
If true, when creating a table using existing data, columns with a low number of distinct values
will have the allowed_values column property populated with random values""",
null,
false));
}

Expand All @@ -143,6 +158,20 @@ public List<PropertyMetadata<?>> getTableProperties()
"Default limit of rows returned from this table if not specified in the query",
null,
defaultLimit -> checkProperty(1 <= defaultLimit, INVALID_TABLE_PROPERTY, "default_limit value must be equal or greater than 1"),
false),
booleanProperty(
TableInfo.SEQUENCE_DETECTION_ENABLED,
"""
If true, when creating a table using existing data, columns with the number of distinct values close to
the number of rows will be treated as sequences""",
null,
false),
booleanProperty(
TableInfo.DICTIONARY_DETECTION_ENABLED,
"""
If true, when creating a table using existing data, columns with a low number of distinct values
will have the allowed_values column property populated with random values""",
null,
false));
}

Expand Down
Loading