diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java index 1ab3c20d129..275d04d6200 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java @@ -30,8 +30,6 @@ import io.trino.spi.connector.ConnectorTableMetadata; import io.trino.spi.connector.ConnectorTableVersion; import io.trino.spi.connector.ConnectorViewDefinition; -import io.trino.spi.connector.Constraint; -import io.trino.spi.connector.ConstraintApplicationResult; import io.trino.spi.connector.LimitApplicationResult; import io.trino.spi.connector.RelationColumnsMetadata; import io.trino.spi.connector.RetryMode; @@ -45,7 +43,6 @@ import io.trino.spi.function.FunctionMetadata; import io.trino.spi.function.SchemaFunctionName; import io.trino.spi.predicate.Domain; -import io.trino.spi.predicate.TupleDomain; import io.trino.spi.security.TrinoPrincipal; import io.trino.spi.statistics.ComputedStatistics; import io.trino.spi.type.BigintType; @@ -152,7 +149,7 @@ public synchronized ConnectorTableHandle getTableHandle(ConnectorSession session } long schemaLimit = (long) schema.properties().getOrDefault(SchemaInfo.DEFAULT_LIMIT_PROPERTY, defaultLimit); long tableLimit = (long) tables.get(tableName).properties().getOrDefault(TableInfo.DEFAULT_LIMIT_PROPERTY, schemaLimit); - return new FakerTableHandle(tableName, TupleDomain.all(), tableLimit); + return new FakerTableHandle(tableName, tableLimit); } @Override @@ -522,62 +519,6 @@ public Optional> applyLimit( true)); } - @Override - public Optional> applyFilter( - ConnectorSession session, - ConnectorTableHandle table, - Constraint constraint) - { - FakerTableHandle fakerTable = (FakerTableHandle) table; - - TupleDomain summary = constraint.getSummary(); - if (summary.isAll()) { - return Optional.empty(); - } - // the only reason not to use isNone is so the linter doesn't complain about not checking an Optional - if (summary.getDomains().isEmpty()) { - throw new IllegalArgumentException("summary cannot be none"); - } - - TupleDomain currentConstraint = fakerTable.constraint(); - if (currentConstraint.getDomains().isEmpty()) { - throw new IllegalArgumentException("currentConstraint is none but should be all!"); - } - - // push down everything, unsupported constraints will throw an exception during data generation - boolean anyUpdated = false; - for (Map.Entry entry : summary.getDomains().get().entrySet()) { - FakerColumnHandle column = (FakerColumnHandle) entry.getKey(); - Domain domain = entry.getValue(); - - if (currentConstraint.getDomains().get().containsKey(column)) { - Domain currentDomain = currentConstraint.getDomains().get().get(column); - // it is important to avoid processing same constraint multiple times - // so that planner doesn't get stuck in a loop - if (currentDomain.equals(domain)) { - continue; - } - // TODO write test cases for this, it doesn't seem to work with IS NULL - currentDomain.union(domain); - } - else { - Map domains = new HashMap<>(currentConstraint.getDomains().get()); - domains.put(column, domain); - currentConstraint = TupleDomain.withColumnDomains(domains); - } - anyUpdated = true; - } - if (!anyUpdated) { - return Optional.empty(); - } - - return Optional.of(new ConstraintApplicationResult<>( - fakerTable.withConstraint(currentConstraint), - TupleDomain.all(), - constraint.getExpression(), - true)); - } - @Override public Collection listFunctions(ConnectorSession session, String schemaName) { diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSource.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSource.java index ed676cf0cc4..d911ebc10db 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSource.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSource.java @@ -19,11 +19,8 @@ import io.trino.spi.PageBuilder; import io.trino.spi.TrinoException; import io.trino.spi.block.BlockBuilder; -import io.trino.spi.connector.ColumnHandle; import io.trino.spi.connector.ConnectorPageSource; -import io.trino.spi.predicate.Domain; import io.trino.spi.predicate.Range; -import io.trino.spi.predicate.TupleDomain; import io.trino.spi.type.CharType; import io.trino.spi.type.DecimalType; import io.trino.spi.type.Decimals; @@ -126,7 +123,6 @@ class FakerPageSource Faker faker, Random random, List columns, - TupleDomain constraint, long offset, long limit) { @@ -136,19 +132,17 @@ class FakerPageSource .stream() .map(FakerColumnHandle::type) .collect(toImmutableList()); - requireNonNull(constraint, "constraint is null"); this.limit = limit; this.generators = columns .stream() - .map(column -> getGenerator(column, constraint, offset)) + .map(column -> getGenerator(column, offset)) .collect(toImmutableList()); this.pageBuilder = new PageBuilder(types); } private Generator getGenerator( FakerColumnHandle column, - TupleDomain constraint, long offset) { if (ROW_ID_COLUMN_NAME.equals(column.name())) { @@ -164,9 +158,7 @@ public void accept(BlockBuilder blockBuilder) }; } - return constraintedValueGenerator( - column, - constraint.getDomains().get().getOrDefault(column, Domain.all(column.type()))); + return constraintedValueGenerator(column); } @Override @@ -230,24 +222,14 @@ public void close() closed = true; } - private Generator constraintedValueGenerator(FakerColumnHandle handle, Domain domain) + private Generator constraintedValueGenerator(FakerColumnHandle handle) { - if (domain.isSingleValue()) { - ObjectWriter singleValueWriter = objectWriter(handle.type()); - return (blockBuilder) -> singleValueWriter.accept(blockBuilder, domain.getSingleValue()); - } - if (domain.getValues().isDiscreteSet() || handle.domain().getValues().isDiscreteSet()) { - List values = domain.getValues().isDiscreteSet() - ? domain.getValues().getDiscreteSet() - : handle.domain().getValues().getDiscreteSet(); + if (handle.domain().getValues().isDiscreteSet()) { + List values = handle.domain().getValues().getDiscreteSet(); ObjectWriter singleValueWriter = objectWriter(handle.type()); return (blockBuilder) -> singleValueWriter.accept(blockBuilder, values.get(random.nextInt(values.size()))); } - if (domain.getValues().getRanges().getRangeCount() > 1) { - // this would require calculating weights for each range to retain uniform distribution - throw new TrinoException(INVALID_ROW_FILTER, "Generating random values from more than one range is not supported"); - } - Generator generator = randomValueGenerator(handle, domain.getValues().getRanges().getSpan()); + Generator generator = randomValueGenerator(handle); if (handle.nullProbability() == 0) { return generator; } @@ -261,10 +243,9 @@ private Generator constraintedValueGenerator(FakerColumnHandle handle, Domain do }; } - private Generator randomValueGenerator(FakerColumnHandle handle, Range predicateRange) + private Generator randomValueGenerator(FakerColumnHandle handle) { - Range range = predicateRange.intersect(handle.domain().getValues().getRanges().getSpan()) - .orElseThrow(() -> new TrinoException(INVALID_ROW_FILTER, "Predicates do not overlap with column min and max properties")); + Range range = handle.domain().getValues().getRanges().getSpan(); if (handle.generator() != null) { if (!range.isAll()) { throw new TrinoException(INVALID_ROW_FILTER, "Predicates for columns with a generator expression are not supported"); diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSourceProvider.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSourceProvider.java index a13c89a0d25..d9eebc39146 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSourceProvider.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerPageSourceProvider.java @@ -66,10 +66,9 @@ public ConnectorPageSource createPageSource( .map(FakerColumnHandle.class::cast) .collect(toImmutableList()); - FakerTableHandle fakerTable = (FakerTableHandle) table; FakerSplit fakerSplit = (FakerSplit) split; Random random = random(fakerSplit.splitNumber()); - return new FakerPageSource(new Faker(locale, random), random, handles, fakerTable.constraint(), fakerSplit.rowsOffset(), fakerSplit.rowsCount()); + return new FakerPageSource(new Faker(locale, random), random, handles, fakerSplit.rowsOffset(), fakerSplit.rowsCount()); } private Random random(long index) diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerTableHandle.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerTableHandle.java index e9535e7126c..8f821dcbbdc 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerTableHandle.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerTableHandle.java @@ -14,29 +14,21 @@ package io.trino.plugin.faker; -import io.trino.spi.connector.ColumnHandle; import io.trino.spi.connector.ConnectorTableHandle; import io.trino.spi.connector.SchemaTableName; -import io.trino.spi.predicate.TupleDomain; import static java.util.Objects.requireNonNull; -public record FakerTableHandle(SchemaTableName schemaTableName, TupleDomain constraint, long limit) +public record FakerTableHandle(SchemaTableName schemaTableName, long limit) implements ConnectorTableHandle { public FakerTableHandle { requireNonNull(schemaTableName, "schemaTableName is null"); - requireNonNull(constraint, "constraint is null"); - } - - public FakerTableHandle withConstraint(TupleDomain constraint) - { - return new FakerTableHandle(schemaTableName, constraint, limit); } public FakerTableHandle withLimit(long limit) { - return new FakerTableHandle(schemaTableName, constraint, limit); + return new FakerTableHandle(schemaTableName, limit); } } diff --git a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java index ef85b434119..b9976e75c6c 100644 --- a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java +++ b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java @@ -311,547 +311,6 @@ void testSelectFunctions() assertQuery(testQuery, "VALUES (true)"); } - @Test - void testSelectRange() - { - @Language("SQL") - String tableQuery = - """ - CREATE TABLE faker.default.all_types_range ( - rnd_bigint bigint NOT NULL, - rnd_integer integer NOT NULL, - rnd_smallint smallint NOT NULL, - rnd_tinyint tinyint NOT NULL, - rnd_boolean boolean NOT NULL, - rnd_date date NOT NULL, - rnd_decimal1 decimal NOT NULL, - rnd_decimal2 decimal(18,5) NOT NULL, - rnd_decimal3 decimal(38,0) NOT NULL, - rnd_decimal4 decimal(38,38) NOT NULL, - rnd_decimal5 decimal(5,2) NOT NULL, - rnd_real real NOT NULL, - rnd_double double NOT NULL, - rnd_interval_day_time interval day to second NOT NULL, - rnd_interval_year interval year to month NOT NULL, - rnd_timestamp timestamp NOT NULL, - rnd_timestamp0 timestamp(0) NOT NULL, - rnd_timestamp6 timestamp(6) NOT NULL, - rnd_timestamp9 timestamp(9) NOT NULL, - rnd_timestamptz timestamp with time zone NOT NULL, - rnd_timestamptz0 timestamp(0) with time zone NOT NULL, - rnd_timestamptz6 timestamp(6) with time zone NOT NULL, - rnd_timestamptz9 timestamp(9) with time zone NOT NULL, - rnd_time time NOT NULL, - rnd_time0 time(0) NOT NULL, - rnd_time6 time(6) NOT NULL, - rnd_time9 time(9) NOT NULL, - rnd_timetz time with time zone NOT NULL, - rnd_timetz0 time(0) with time zone NOT NULL, - rnd_timetz6 time(6) with time zone NOT NULL, - rnd_timetz9 time(9) with time zone NOT NULL, - rnd_timetz12 time(12) with time zone NOT NULL, - rnd_varbinary varbinary NOT NULL, - rnd_varchar varchar NOT NULL, - rnd_nvarchar varchar(1000) NOT NULL, - rnd_char char NOT NULL, - rnd_nchar char(1000) NOT NULL, - rnd_ipaddress ipaddress NOT NULL, - rnd_uuid uuid NOT NULL)"""; - assertUpdate(tableQuery); - - @Language("SQL") - String testQuery; - - // inclusive ranges (BETWEEN) that produce only 2 values - // obtained using `Math.nextUp((float) 0.0)` - testQuery = - """ - SELECT - count(distinct rnd_bigint), - count(distinct rnd_integer), - count(distinct rnd_smallint), - count(distinct rnd_tinyint), - count(distinct rnd_date), - count(distinct rnd_decimal1), - count(distinct rnd_decimal2), - count(distinct rnd_decimal3), - count(distinct rnd_decimal4), - count(distinct rnd_decimal5), - count(distinct rnd_real), - count(distinct rnd_double), - count(distinct rnd_interval_day_time), - count(distinct rnd_interval_year), - count(distinct rnd_timestamp), - count(distinct rnd_timestamp0), - count(distinct rnd_timestamp6), - count(distinct rnd_timestamp9), - count(distinct rnd_timestamptz), - count(distinct rnd_timestamptz0), - count(distinct rnd_timestamptz6), - count(distinct rnd_timestamptz9), - count(distinct rnd_time), - count(distinct rnd_time0), - count(distinct rnd_time6), - count(distinct rnd_time9), - count(distinct rnd_timetz), - count(distinct rnd_timetz0), - count(distinct rnd_timetz6), - count(distinct rnd_timetz9) - FROM all_types_range - WHERE 1=1 - AND rnd_bigint BETWEEN 0 AND 1 - AND rnd_integer BETWEEN 0 AND 1 - AND rnd_smallint BETWEEN 0 AND 1 - AND rnd_tinyint BETWEEN 0 AND 1 - AND rnd_date BETWEEN DATE '2022-03-01' AND DATE '2022-03-02' - AND rnd_decimal1 BETWEEN 0 AND 1 - AND rnd_decimal2 BETWEEN 0.00000 AND 0.00001 - AND rnd_decimal3 BETWEEN 0 AND 1 - AND rnd_decimal4 BETWEEN DECIMAL '0.00000000000000000000000000000000000000' AND DECIMAL '0.00000000000000000000000000000000000001' - AND rnd_decimal5 BETWEEN 0.00 AND 0.01 - AND rnd_real BETWEEN REAL '0.0' AND REAL '1.4E-45' - AND rnd_double BETWEEN DOUBLE '0.0' AND DOUBLE '4.9E-324' - AND rnd_interval_day_time BETWEEN INTERVAL '0.000' SECOND AND INTERVAL '0.001' SECOND - AND rnd_interval_year BETWEEN INTERVAL '0' MONTH AND INTERVAL '1' MONTH - AND rnd_timestamp BETWEEN TIMESTAMP '2022-03-21 00:00:00.000' AND TIMESTAMP '2022-03-21 00:00:00.001' - AND rnd_timestamp0 BETWEEN TIMESTAMP '2022-03-21 00:00:00' AND TIMESTAMP '2022-03-21 00:00:01' - AND rnd_timestamp6 BETWEEN TIMESTAMP '2022-03-21 00:00:00.000000' AND TIMESTAMP '2022-03-21 00:00:00.000001' - AND rnd_timestamp9 BETWEEN TIMESTAMP '2022-03-21 00:00:00.000000000' AND TIMESTAMP '2022-03-21 00:00:00.000000001' - AND rnd_timestamptz BETWEEN TIMESTAMP '2022-03-21 00:00:00.000 +01:00' AND TIMESTAMP '2022-03-21 00:00:00.001 +01:00' - AND rnd_timestamptz0 BETWEEN TIMESTAMP '2022-03-21 00:00:00 +01:00' AND TIMESTAMP '2022-03-21 00:00:01 +01:00' - AND rnd_timestamptz6 BETWEEN TIMESTAMP '2022-03-21 00:00:00.000000 +01:00' AND TIMESTAMP '2022-03-21 00:00:00.000001 +01:00' - AND rnd_timestamptz9 BETWEEN TIMESTAMP '2022-03-21 00:00:00.000000000 +01:00' AND TIMESTAMP '2022-03-21 00:00:00.000000001 +01:00' - AND rnd_time BETWEEN TIME '01:02:03.456' AND TIME '01:02:03.457' - AND rnd_time0 BETWEEN TIME '01:02:03' AND TIME '01:02:04' - AND rnd_time6 BETWEEN TIME '01:02:03.000456' AND TIME '01:02:03.000457' - AND rnd_time9 BETWEEN TIME '01:02:03.000000456' AND TIME '01:02:03.000000457' - AND rnd_timetz BETWEEN TIME '01:02:03.456 +01:00' AND TIME '01:02:03.457 +01:00' - AND rnd_timetz0 BETWEEN TIME '01:02:03 +01:00' AND TIME '01:02:04 +01:00' - AND rnd_timetz6 BETWEEN TIME '01:02:03.000456 +01:00' AND TIME '01:02:03.000457 +01:00' - AND rnd_timetz9 BETWEEN TIME '01:02:03.000000456 +01:00' AND TIME '01:02:03.000000457 +01:00'\s"""; - assertQuery(testQuery, - """ - VALUES (2, - 2, - 2, - 2, - -- date - 2, - -- decimal - 2, - 2, - 2, - 2, - 2, - -- real, double - 2, - 2, - -- intervals - 2, - 2, - -- timestamps - 2, - 2, - 2, - 2, - -- timestamps with time zone - 2, - 2, - 2, - 2, - -- time - 2, - 2, - 2, - 2, - -- time with time zone - 2, - 2, - 2, - 2) - """); - - // exclusive ranges that produce only 1 value - // obtained using `Math.nextUp((float) 0.0)` - testQuery = - """ - SELECT - count(distinct rnd_bigint), - count(distinct rnd_integer), - count(distinct rnd_smallint), - count(distinct rnd_tinyint), - count(distinct rnd_date), - count(distinct rnd_decimal1), - count(distinct rnd_decimal2), - count(distinct rnd_decimal3), - count(distinct rnd_decimal4), - count(distinct rnd_decimal5), - count(distinct rnd_real), - count(distinct rnd_double), - count(distinct rnd_interval_day_time), - count(distinct rnd_interval_year), - count(distinct rnd_timestamp), - count(distinct rnd_timestamp0), - count(distinct rnd_timestamp6), - count(distinct rnd_timestamp9), - count(distinct rnd_timestamptz), - count(distinct rnd_timestamptz0), - count(distinct rnd_timestamptz6), - count(distinct rnd_timestamptz9), - count(distinct rnd_time), - count(distinct rnd_time0), - count(distinct rnd_time6), - count(distinct rnd_time9), - count(distinct rnd_timetz), - count(distinct rnd_timetz0), - count(distinct rnd_timetz6), - count(distinct rnd_timetz9) - FROM all_types_range - WHERE 1=1 - AND rnd_bigint > 0 AND rnd_bigint < 2 - AND rnd_integer > 0 AND rnd_integer < 2 - AND rnd_smallint > 0 AND rnd_smallint < 2 - AND rnd_tinyint > 0 AND rnd_tinyint < 2 - AND rnd_date > DATE '2022-03-01' AND rnd_date < DATE '2022-03-03' - AND rnd_decimal1 > 0 AND rnd_decimal1 < 2 - AND rnd_decimal2 > 0.00000 AND rnd_decimal2 < 0.00002 - AND rnd_decimal3 > 0 AND rnd_decimal3 < 2 - AND rnd_decimal4 > DECIMAL '0.00000000000000000000000000000000000000' AND rnd_decimal4 < DECIMAL '0.00000000000000000000000000000000000002' - AND rnd_decimal5 > 0.00 AND rnd_decimal5 < 0.02 - AND rnd_real > REAL '0.0' AND rnd_real < REAL '2.8E-45' - AND rnd_double > DOUBLE '0.0' AND rnd_double < DOUBLE '1.0E-323' - AND rnd_interval_day_time > INTERVAL '0.000' SECOND AND rnd_interval_day_time < INTERVAL '0.002' SECOND - AND rnd_interval_year > INTERVAL '0' MONTH AND rnd_interval_year < INTERVAL '2' MONTH - AND rnd_timestamp > TIMESTAMP '2022-03-21 00:00:00.000' AND rnd_timestamp < TIMESTAMP '2022-03-21 00:00:00.002' - AND rnd_timestamp0 > TIMESTAMP '2022-03-21 00:00:00' AND rnd_timestamp0 < TIMESTAMP '2022-03-21 00:00:02' - AND rnd_timestamp6 > TIMESTAMP '2022-03-21 00:00:00.000000' AND rnd_timestamp6 < TIMESTAMP '2022-03-21 00:00:00.000002' - AND rnd_timestamp9 > TIMESTAMP '2022-03-21 00:00:00.000000000' AND rnd_timestamp9 < TIMESTAMP '2022-03-21 00:00:00.000000002' - AND rnd_timestamptz > TIMESTAMP '2022-03-21 00:00:00.000 +01:00' AND rnd_timestamptz < TIMESTAMP '2022-03-21 00:00:00.002 +01:00' - AND rnd_timestamptz0 > TIMESTAMP '2022-03-21 00:00:00 +01:00' AND rnd_timestamptz0 < TIMESTAMP '2022-03-21 00:00:02 +01:00' - AND rnd_timestamptz6 > TIMESTAMP '2022-03-21 00:00:00.000000 +01:00' AND rnd_timestamptz6 < TIMESTAMP '2022-03-21 00:00:00.000002 +01:00' - AND rnd_timestamptz9 > TIMESTAMP '2022-03-21 00:00:00.000000000 +01:00' AND rnd_timestamptz9 < TIMESTAMP '2022-03-21 00:00:00.000000002 +01:00' - AND rnd_time > TIME '01:02:03.456' AND rnd_time < TIME '01:02:03.458' - AND rnd_time0 > TIME '01:02:03' AND rnd_time0 < TIME '01:02:05' - AND rnd_time6 > TIME '01:02:03.000456' AND rnd_time6 < TIME '01:02:03.000458' - AND rnd_time9 > TIME '01:02:03.000000456' AND rnd_time9 < TIME '01:02:03.000000458' - AND rnd_timetz > TIME '01:02:03.456 +01:00' AND rnd_timetz < TIME '01:02:03.458 +01:00' - AND rnd_timetz0 > TIME '01:02:03 +01:00' AND rnd_timetz0 < TIME '01:02:05 +01:00' - AND rnd_timetz6 > TIME '01:02:03.000456 +01:00' AND rnd_timetz6 < TIME '01:02:03.000458 +01:00' - AND rnd_timetz9 > TIME '01:02:03.000000456 +01:00' AND rnd_timetz9 < TIME '01:02:03.000000458 +01:00'\s"""; - assertQuery(testQuery, - """ - VALUES (1, - 1, - 1, - 1, - -- date - 1, - -- decimal - 1, - 1, - 1, - 1, - 1, - -- real, double - 1, - 1, - -- intervals - 1, - 1, - -- timestamps - 1, - 1, - 1, - 1, - -- timestamps with time zone - 1, - 1, - 1, - 1, - -- time - 1, - 1, - 1, - 1, - -- time with time zone - 1, - 1, - 1, - 1) - """); - - // inclusive range to get the min low bound - testQuery = - """ - SELECT - count(distinct rnd_bigint), - count(distinct rnd_integer), - count(distinct rnd_smallint), - count(distinct rnd_tinyint), - count(distinct rnd_date), - count(distinct rnd_decimal1), - count(distinct rnd_decimal2), - count(distinct rnd_decimal3), - count(distinct rnd_decimal4), - count(distinct rnd_decimal5), - count(distinct rnd_real), - count(distinct rnd_double), - -- interval literals can't represent smallest possible values allowed by the engine - --count(distinct rnd_interval_day_time), - --count(distinct rnd_interval_year), - -- can't count timestamps because their extreme values cannot be expressed as literals - count(distinct rnd_time), - count(distinct rnd_time0), - count(distinct rnd_time6), - count(distinct rnd_time9), - count(distinct rnd_timetz), - count(distinct rnd_timetz0), - count(distinct rnd_timetz6), - count(distinct rnd_timetz9) - FROM all_types_range - WHERE 1=1 - AND rnd_bigint <= -9223372036854775808 - AND rnd_integer <= -2147483648 - AND rnd_smallint <= -32768 - AND rnd_tinyint <= -128 - -- TODO it actually returns -5877641-06-23 - there's definitely some overflow happening in the engine - AND rnd_date <= DATE '-5877641-06-23' - AND rnd_decimal1 <= DECIMAL '-99999999999999999999999999999999999999' - AND rnd_decimal2 <= DECIMAL '-9999999999999.99999' - AND rnd_decimal3 <= DECIMAL '-99999999999999999999999999999999999999' - AND rnd_decimal4 <= DECIMAL '-0.99999999999999999999999999999999999999' - -- TODO it actually retdurns '-999.98' - AND rnd_decimal5 <= DECIMAL '-999.99' - AND rnd_real <= REAL '1.4E-45' - AND rnd_double <= DOUBLE '4.9E-324' - -- interval literals can't represent smallest possible values allowed by the engine - --AND rnd_interval_day_time <= INTERVAL '-2147483647' SECOND - --AND rnd_interval_year <= INTERVAL '-2147483647' MONTH - AND rnd_time <= TIME '00:00:00.000' - AND rnd_time0 <= TIME '00:00:00' - AND rnd_time6 <= TIME '00:00:00.000000' - AND rnd_time9 <= TIME '00:00:00.000000000' - AND rnd_timetz <= TIME '00:00:00.000 +01:00' - AND rnd_timetz0 <= TIME '00:00:00 +01:00' - AND rnd_timetz6 <= TIME '00:00:00.000000 +01:00' - AND rnd_timetz9 <= TIME '00:00:00.000000000 +01:00' - """; - assertQuery(testQuery, - """ - VALUES (1, - 1, - 1, - 1, - -- date - 1, - -- decimal - 1, - 1, - 1, - 1, - 1, - -- real, double - 1, - 1, - -- intervals - --1, - --1, - -- time - 1, - 1, - 1, - 1, - -- time with time zone - 1, - 1, - 1, - 1) - """); - - // exclusive range to get the max high bound - - assertUpdate("DROP TABLE faker.default.all_types_range"); - } - - @Test - void testSelectIn() - { - @Language("SQL") - String tableQuery = - """ - CREATE TABLE faker.default.all_types_in ( - rnd_bigint bigint NOT NULL, - rnd_integer integer NOT NULL, - rnd_smallint smallint NOT NULL, - rnd_tinyint tinyint NOT NULL, - rnd_boolean boolean NOT NULL, - rnd_date date NOT NULL, - rnd_decimal1 decimal NOT NULL, - rnd_decimal2 decimal(18,5) NOT NULL, - rnd_decimal3 decimal(38,0) NOT NULL, - rnd_decimal4 decimal(38,38) NOT NULL, - rnd_decimal5 decimal(5,2) NOT NULL, - rnd_real real NOT NULL, - rnd_double double NOT NULL, - rnd_interval_day_time interval day to second NOT NULL, - rnd_interval_year interval year to month NOT NULL, - rnd_timestamp timestamp NOT NULL, - rnd_timestamp0 timestamp(0) NOT NULL, - rnd_timestamp6 timestamp(6) NOT NULL, - rnd_timestamp9 timestamp(9) NOT NULL, - rnd_timestamptz timestamp with time zone NOT NULL, - rnd_timestamptz0 timestamp(0) with time zone NOT NULL, - rnd_timestamptz6 timestamp(6) with time zone NOT NULL, - rnd_timestamptz9 timestamp(9) with time zone NOT NULL, - rnd_time time NOT NULL, - rnd_time0 time(0) NOT NULL, - rnd_time6 time(6) NOT NULL, - rnd_time9 time(9) NOT NULL, - rnd_timetz time with time zone NOT NULL, - rnd_timetz0 time(0) with time zone NOT NULL, - rnd_timetz6 time(6) with time zone NOT NULL, - rnd_timetz9 time(9) with time zone NOT NULL, - rnd_timetz12 time(12) with time zone NOT NULL, - rnd_varbinary varbinary NOT NULL, - rnd_varchar varchar NOT NULL, - rnd_nvarchar varchar(1000) NOT NULL, - rnd_ipaddress ipaddress NOT NULL, - rnd_uuid uuid NOT NULL)"""; - assertUpdate(tableQuery); - - @Language("SQL") - String testQuery; - - // inclusive ranges (BETWEEN) that produce only 2 values - // obtained using `Math.nextUp((float) 0.0)` - testQuery = - """ - SELECT - count(distinct rnd_bigint), - count(distinct rnd_integer), - count(distinct rnd_smallint), - count(distinct rnd_tinyint), - count(distinct rnd_date), - count(distinct rnd_decimal1), - count(distinct rnd_decimal2), - count(distinct rnd_decimal3), - count(distinct rnd_decimal4), - count(distinct rnd_decimal5), - count(distinct rnd_real), - count(distinct rnd_double), - count(distinct rnd_interval_day_time), - count(distinct rnd_interval_year), - count(distinct rnd_timestamp), - count(distinct rnd_timestamp0), - count(distinct rnd_timestamp6), - count(distinct rnd_timestamp9), - count(distinct rnd_timestamptz), - count(distinct rnd_timestamptz0), - count(distinct rnd_timestamptz6), - count(distinct rnd_timestamptz9), - count(distinct rnd_time), - count(distinct rnd_time0), - count(distinct rnd_time6), - count(distinct rnd_time9), - count(distinct rnd_timetz), - count(distinct rnd_timetz0), - count(distinct rnd_timetz6), - count(distinct rnd_timetz9), - count(distinct rnd_varbinary), - count(distinct rnd_varchar), - count(distinct rnd_nvarchar), - count(distinct rnd_ipaddress), - count(distinct rnd_uuid) - FROM all_types_in - WHERE 1=1 - AND rnd_bigint IN (0, 1) - AND rnd_integer IN (0, 1) - AND rnd_smallint IN (0, 1) - AND rnd_tinyint IN (0, 1) - AND rnd_date IN (DATE '2022-03-01', DATE '2022-03-02') - AND rnd_decimal1 IN (0, 1) - AND rnd_decimal2 IN (0.00000, 0.00001) - AND rnd_decimal3 IN (0, 1) - AND rnd_decimal4 IN (DECIMAL '0.00000000000000000000000000000000000000', DECIMAL '0.00000000000000000000000000000000000001') - AND rnd_decimal5 IN (0.00, 0.01) - AND rnd_real IN (REAL '0.0', REAL '1.4E-45') - AND rnd_double IN (DOUBLE '0.0', DOUBLE '4.9E-324') - AND rnd_interval_day_time IN (INTERVAL '0.000' SECOND, INTERVAL '0.001' SECOND) - AND rnd_interval_year IN (INTERVAL '0' MONTH, INTERVAL '1' MONTH) - AND rnd_timestamp IN (TIMESTAMP '2022-03-21 00:00:00.000', TIMESTAMP '2022-03-21 00:00:00.001') - AND rnd_timestamp0 IN (TIMESTAMP '2022-03-21 00:00:00', TIMESTAMP '2022-03-21 00:00:01') - AND rnd_timestamp6 IN (TIMESTAMP '2022-03-21 00:00:00.000000', TIMESTAMP '2022-03-21 00:00:00.000001') - AND rnd_timestamp9 IN (TIMESTAMP '2022-03-21 00:00:00.000000000', TIMESTAMP '2022-03-21 00:00:00.000000001') - AND rnd_timestamptz IN (TIMESTAMP '2022-03-21 00:00:00.000 +01:00', TIMESTAMP '2022-03-21 00:00:00.001 +01:00') - AND rnd_timestamptz0 IN (TIMESTAMP '2022-03-21 00:00:00 +01:00', TIMESTAMP '2022-03-21 00:00:01 +01:00') - AND rnd_timestamptz6 IN (TIMESTAMP '2022-03-21 00:00:00.000000 +01:00', TIMESTAMP '2022-03-21 00:00:00.000001 +01:00') - AND rnd_timestamptz9 IN (TIMESTAMP '2022-03-21 00:00:00.000000000 +01:00', TIMESTAMP '2022-03-21 00:00:00.000000001 +01:00') - AND rnd_time IN (TIME '01:02:03.456', TIME '01:02:03.457') - AND rnd_time0 IN (TIME '01:02:03', TIME '01:02:04') - AND rnd_time6 IN (TIME '01:02:03.000456', TIME '01:02:03.000457') - AND rnd_time9 IN (TIME '01:02:03.000000456', TIME '01:02:03.000000457') - AND rnd_timetz IN (TIME '01:02:03.456 +01:00', TIME '01:02:03.457 +01:00') - AND rnd_timetz0 IN (TIME '01:02:03 +01:00', TIME '01:02:04 +01:00') - AND rnd_timetz6 IN (TIME '01:02:03.000456 +01:00', TIME '01:02:03.000457 +01:00') - AND rnd_timetz9 IN (TIME '01:02:03.000000456 +01:00', TIME '01:02:03.000000457 +01:00') - AND rnd_varbinary IN (x'ff', x'00') - AND rnd_varchar IN ('aa', 'bb') - AND rnd_nvarchar IN ('aa', 'bb') - AND rnd_ipaddress IN (IPADDRESS '0.0.0.0', IPADDRESS '1.2.3.4') - AND rnd_uuid IN (UUID '1fc74d96-0216-449b-a145-455578a9eaa5', UUID '3ee49ede-0026-45e4-ba06-08404f794557') - """; - assertQuery(testQuery, - """ - VALUES (2, - 2, - 2, - 2, - -- date - 2, - -- decimal - 2, - 2, - 2, - 2, - 2, - -- real, double - 2, - 2, - -- intervals - 2, - 2, - -- timestamps - 2, - 2, - 2, - 2, - -- timestamps with time zone - 2, - 2, - 2, - 2, - -- time - 2, - 2, - 2, - 2, - -- time with time zone - 2, - 2, - 2, - 2, - -- character types - 2, - 2, - 2, - -- ip, uuid - 2, - 2) - """); - - assertUpdate("DROP TABLE faker.default.all_types_in"); - } - @Test void testSelectRangeProperties() { diff --git a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerSplitManager.java b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerSplitManager.java index 898d16cf25f..c5a4be4a5e0 100644 --- a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerSplitManager.java +++ b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerSplitManager.java @@ -18,7 +18,6 @@ import io.trino.spi.connector.Constraint; import io.trino.spi.connector.DynamicFilter; import io.trino.spi.connector.SchemaTableName; -import io.trino.spi.predicate.TupleDomain; import io.trino.testing.TestingConnectorSession; import io.trino.testing.TestingTransactionHandle; import org.junit.jupiter.api.Test; @@ -39,7 +38,7 @@ void testSplits() ConnectorSplitSource splitSource = new FakerSplitManager().getSplits( TestingTransactionHandle.create(), TestingConnectorSession.SESSION, - new FakerTableHandle(new SchemaTableName("schema", "table"), TupleDomain.all(), expectedRows), + new FakerTableHandle(new SchemaTableName("schema", "table"), expectedRows), DynamicFilter.EMPTY, Constraint.alwaysTrue()); List splits = splitSource.getNextBatch(1_000_000).get().getSplits();