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 @@ -23,6 +23,7 @@
import io.trino.spi.block.BlockEncodingSerde;
import io.trino.spi.block.TestingBlockEncodingSerde;
import io.trino.spi.type.ArrayType;
import io.trino.spi.type.LongTimestamp;
import io.trino.spi.type.MapType;
import io.trino.spi.type.RowType;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -65,6 +66,7 @@
import static java.lang.String.format;
import static java.util.Collections.unmodifiableSortedMap;
import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
Expand All @@ -77,7 +79,7 @@ public abstract class AbstractTestType

private final Class<?> objectValueType;
private final Block testBlock;
private final Type type;
protected final Type type;
private final TypeOperators typeOperators;
protected final BlockTypeOperators blockTypeOperators;
private final BlockPositionEqual equalOperator;
Expand Down Expand Up @@ -186,6 +188,13 @@ public void testBlock()
}
}

@Test
public void testRange()
{
assertThat(type.getRange())
.isEmpty();
}

protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue)
{
long hash = 0;
Expand Down Expand Up @@ -473,6 +482,9 @@ private static Object getNonNullValueForType(Type type)
if (type.getJavaType() == Slice.class) {
return Slices.utf8Slice("_");
}
if (type.getJavaType() == LongTimestamp.class) {
return new LongTimestamp(1, 0);
}
if (type instanceof ArrayType) {
ArrayType arrayType = (ArrayType) type;
Type elementType = arrayType.getElementType();
Expand Down
10 changes: 10 additions & 0 deletions core/trino-main/src/test/java/io/trino/type/TestBigintType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type.Range;

import static io.trino.spi.type.BigintType.BIGINT;
import static org.testng.Assert.assertEquals;

public class TestBigintType
extends AbstractTestType
Expand Down Expand Up @@ -48,4 +50,12 @@ protected Object getGreaterValue(Object value)
{
return ((Long) value) + 1;
}

@Override
public void testRange()
{
Range range = type.getRange().orElseThrow();
assertEquals(range.getMin(), Long.MIN_VALUE);
assertEquals(range.getMax(), Long.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.type;

import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type;
import io.trino.spi.type.VarcharType;

import static io.trino.spi.type.VarcharType.createVarcharType;
import static org.testng.Assert.assertEquals;

public class TestBoundedVarcharType
extends AbstractTestType
{
public TestBoundedVarcharType()
{
super(createVarcharType(6), String.class, createTestBlock(createVarcharType(6)));
}

private static Block createTestBlock(VarcharType type)
{
BlockBuilder blockBuilder = type.createBlockBuilder(null, 15);
type.writeString(blockBuilder, "apple");
type.writeString(blockBuilder, "apple");
type.writeString(blockBuilder, "apple");
type.writeString(blockBuilder, "banana");
type.writeString(blockBuilder, "banana");
type.writeString(blockBuilder, "banana");
type.writeString(blockBuilder, "banana");
type.writeString(blockBuilder, "banana");
type.writeString(blockBuilder, "cherry");
type.writeString(blockBuilder, "cherry");
type.writeString(blockBuilder, "date");
return blockBuilder.build();
}

@Override
protected Object getGreaterValue(Object value)
{
return Slices.utf8Slice(((Slice) value).toStringUtf8() + "_");
}

@Override
public void testRange()
{
Type.Range range = type.getRange().orElseThrow();

String expectedMax = new StringBuilder()
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.toString();

assertEquals(range.getMin(), Slices.utf8Slice(""));
assertEquals(range.getMax(), Slices.utf8Slice(expectedMax));
}
}
10 changes: 10 additions & 0 deletions core/trino-main/src/test/java/io/trino/type/TestIntegerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type.Range;

import static io.trino.spi.type.IntegerType.INTEGER;
import static org.testng.Assert.assertEquals;

public class TestIntegerType
extends AbstractTestType
Expand Down Expand Up @@ -48,4 +50,12 @@ protected Object getGreaterValue(Object value)
{
return ((Long) value) + 1;
}

@Override
public void testRange()
{
Range range = type.getRange().orElseThrow();
assertEquals(range.getMin(), (long) Integer.MIN_VALUE);
assertEquals(range.getMax(), (long) Integer.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.type;

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.LongTimestamp;
import io.trino.spi.type.SqlTimestamp;

import static io.trino.spi.type.TimestampType.TIMESTAMP_NANOS;

public class TestLongTimestampType
extends AbstractTestType
{
public TestLongTimestampType()
{
super(TIMESTAMP_NANOS, SqlTimestamp.class, createTestBlock());
}

public static Block createTestBlock()
{
BlockBuilder blockBuilder = TIMESTAMP_NANOS.createBlockBuilder(null, 15);
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(1111_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(1111_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(1111_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(2222_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(2222_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(2222_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(2222_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(2222_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(3333_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(3333_123, 123_000));
TIMESTAMP_NANOS.writeObject(blockBuilder, new LongTimestamp(4444_123, 123_000));
return blockBuilder.build();
}

@Override
protected Object getGreaterValue(Object value)
{
LongTimestamp timestamp = (LongTimestamp) value;
return new LongTimestamp(timestamp.getEpochMicros() + 1, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS;

public class TestTimestampType
public class TestShortTimestampType
extends AbstractTestType
{
public TestTimestampType()
public TestShortTimestampType()
{
super(TIMESTAMP_MILLIS, SqlTimestamp.class, createTestBlock());
}
Expand All @@ -47,6 +47,6 @@ public static Block createTestBlock()
@Override
protected Object getGreaterValue(Object value)
{
return ((Long) value) + 1;
return ((Long) value) + 1_000;
}
}
10 changes: 10 additions & 0 deletions core/trino-main/src/test/java/io/trino/type/TestSmallintType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type.Range;

import static io.trino.spi.type.SmallintType.SMALLINT;
import static org.testng.Assert.assertEquals;

public class TestSmallintType
extends AbstractTestType
Expand Down Expand Up @@ -48,4 +50,12 @@ protected Object getGreaterValue(Object value)
{
return ((Long) value) + 1;
}

@Override
public void testRange()
{
Range range = type.getRange().orElseThrow();
assertEquals(range.getMin(), (long) Short.MIN_VALUE);
assertEquals(range.getMax(), (long) Short.MAX_VALUE);
}
}
10 changes: 10 additions & 0 deletions core/trino-main/src/test/java/io/trino/type/TestTinyintType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type.Range;

import static io.trino.spi.type.TinyintType.TINYINT;
import static org.testng.Assert.assertEquals;

public class TestTinyintType
extends AbstractTestType
Expand Down Expand Up @@ -48,4 +50,12 @@ protected Object getGreaterValue(Object value)
{
return ((Long) value) + 1;
}

@Override
public void testRange()
{
Range range = type.getRange().orElseThrow();
assertEquals(range.getMin(), (long) Byte.MIN_VALUE);
assertEquals(range.getMax(), (long) Byte.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@
import io.airlift.slice.Slices;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.type.Type;
import io.trino.spi.type.VarcharType;
import org.testng.annotations.Test;

import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.spi.type.VarcharType.createVarcharType;
import static org.testng.Assert.assertEquals;

public class TestVarcharType
public class TestUnboundedVarcharType
extends AbstractTestType
{
public TestVarcharType()
public TestUnboundedVarcharType()
{
super(VARCHAR, String.class, createTestBlock());
}

public static Block createTestBlock()
private static Block createTestBlock()
{
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 15);
VARCHAR.writeString(blockBuilder, "apple");
Expand All @@ -55,23 +50,4 @@ protected Object getGreaterValue(Object value)
{
return Slices.utf8Slice(((Slice) value).toStringUtf8() + "_");
}

@Test
public void testRange()
{
VarcharType type = createVarcharType(5);

Type.Range range = type.getRange().get();

String expectedMax = new StringBuilder()
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.appendCodePoint(Character.MAX_CODE_POINT)
.toString();

assertEquals(Slices.utf8Slice(""), range.getMin());
assertEquals(Slices.utf8Slice(expectedMax), range.getMax());
}
}