diff --git a/pixels-core/src/main/java/io/pixelsdb/pixels/core/TypeDescription.java b/pixels-core/src/main/java/io/pixelsdb/pixels/core/TypeDescription.java index 6bf3e1fe3b..d1a3d17733 100644 --- a/pixels-core/src/main/java/io/pixelsdb/pixels/core/TypeDescription.java +++ b/pixels-core/src/main/java/io/pixelsdb/pixels/core/TypeDescription.java @@ -35,7 +35,6 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.*; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -477,147 +476,21 @@ public static TypeDescription createSchemaFromStrings(List fieldNames ,L for (int i = 0; i < fieldNames.size(); i++) { String typeName = typeNames.get(i); - TypeDescription fieldType = createFiledFromString(typeName); + TypeDescription fieldType = parseTypeExpression(typeName); schema.addField(fieldNames.get(i), fieldType); } return schema; } - public static TypeDescription createFiledFromString(String originTypeName) + private static TypeDescription parseTypeExpression(String typeName) { - TypeDescription fieldType; - String typeName = originTypeName.trim().toLowerCase(); - if (typeName.startsWith("decimal")) - { - Matcher matcher = Pattern.compile("decimal\\((\\d+),(\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int precision = Integer.parseInt(matcher.group(1)); - int scale = Integer.parseInt(matcher.group(2)); - fieldType = TypeDescription.createDecimal(precision, scale); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("varchar")) - { - Matcher matchar = Pattern.compile("varchar\\((\\d+)\\)").matcher(typeName); - if (matchar.matches()) - { - int maxLength = Integer.parseInt(matchar.group(1)); - fieldType = TypeDescription.createVarchar(maxLength); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("char")) - { - Matcher matcher = Pattern.compile("char\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int maxLength = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createChar(maxLength); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("varbinary")) - { - Matcher matcher = Pattern.compile("varbinary\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int maxLength = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createVarbinary(maxLength); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("binary")) - { - Matcher matcher = Pattern.compile("binary\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int maxLength = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createBinary(maxLength); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("timestamp")) - { - Matcher matcher = Pattern.compile("timestamp\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int precision = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createTimestamp(precision); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("time")) - { - Matcher matcher = Pattern.compile("time\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int precision = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createTime(precision); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else if (typeName.startsWith("vector") || typeName.startsWith("array")) - { - Matcher matcher = Pattern.compile("(vector|array)\\((\\d+)\\)").matcher(typeName); - if (matcher.matches()) - { - int dimension = Integer.parseInt(matcher.group(1)); - fieldType = TypeDescription.createVector(dimension); - } else - { - throw new IllegalArgumentException("Unknown type: " + typeName); - } - } else + StringPosition source = new StringPosition(typeName.replaceAll("\\s", "")); + TypeDescription result = parseType(source); + if (source.position != source.length) { - switch (typeName) - { - case "boolean": - fieldType = TypeDescription.createBoolean(); - break; - case "tinyint": - case "byte": - fieldType = TypeDescription.createByte(); - break; - case "smallint": - case "short": - fieldType = TypeDescription.createShort(); - break; - case "integer": - case "int": - fieldType = TypeDescription.createInt(); - break; - case "bigint": - case "long": - fieldType = TypeDescription.createLong(); - break; - case "float": - case "real": - fieldType = TypeDescription.createFloat(); - break; - case "double": - fieldType = TypeDescription.createDouble(); - break; - case "string": - fieldType = TypeDescription.createString(); - break; - case "date": - fieldType = TypeDescription.createDate(); - break; - default: - throw new IllegalArgumentException("Unknown type: " + typeName); - } + throw new IllegalArgumentException("Extra characters at " + source); } - - return fieldType; + return result; } static class StringPosition @@ -836,7 +709,9 @@ private static void parseStruct(TypeDescription type, StringPosition source) private static TypeDescription parseType(StringPosition source) { + int categoryStart = source.position; TypeDescription result = new TypeDescription(parseCategory(source)); + String categoryName = source.value.substring(categoryStart, source.position); switch (result.getCategory()) { case BOOLEAN: @@ -860,6 +735,7 @@ private static TypeDescription parseType(StringPosition source) { result.withPrecision(DEFAULT_TIME_PRECISION); } + break; case TIMESTAMP: if (consumeChar(source, '(')) { @@ -922,32 +798,34 @@ else if (result.getCategory() == Category.CHAR) parseStruct(result, source); break; case VECTOR: + { + // Handle the Trino representation. The array element type must be double. + if ("array".equalsIgnoreCase(categoryName)) { - // handle type string passed from trino. Check that the type is double(array). - if (source.value.contains("array")) { - if (consumeChar(source, '(')) - { - // the array type must be double - result.checkElementType(source); - result.withDimension(DEFAULT_VECTOR_DIMENSION); - } + requireChar(source, '('); + result.checkElementType(source); + result.withDimension(DEFAULT_VECTOR_DIMENSION); + } + // Handle the Pixels representation vector(d), where d is optional. + else if ("vector".equalsIgnoreCase(categoryName)) + { + if (consumeChar(source, '(')) + { + result.withDimension(parseInt(source)); + requireChar(source, ')'); } - // handle type string passed from Pixels writer, should be vector(d), where (d) specifies that - // this column has dimension d, and is optional - else if (source.value.contains("vector")) { - if (consumeChar(source, '(')) { - // with dimension specified - result.withDimension(parseInt(source)); - requireChar(source, ')'); - } else { - result.withDimension(DEFAULT_VECTOR_DIMENSION); - } - } else { - throw new IllegalArgumentException("Unknown type string" + - result + " at " + source); + else + { + result.withDimension(DEFAULT_VECTOR_DIMENSION); } } + else + { + throw new IllegalArgumentException("Unknown type string" + + result + " at " + source); + } break; + } default: throw new IllegalArgumentException("Unknown type " + result.getCategory() + " at " + source); @@ -971,14 +849,7 @@ public static TypeDescription fromString(String typeName) { return null; } - StringPosition source = new StringPosition( // remove whitespaces (if any) - typeName.replaceAll("\\s", "")); - TypeDescription result = parseType(source); - if (source.position != source.length) - { - throw new IllegalArgumentException("Extra characters at " + source); - } - return result; + return parseTypeExpression(typeName); } /** @@ -1826,19 +1697,32 @@ public static boolean match(int mode1, int mode2) */ public byte[] convertColumnVectorToByte(ColumnVector col, int row) { + if (col.isNull[row]) + { + return null; + } + switch (getCategory()) { case BOOLEAN: case BYTE: - return new byte[]{(byte) ((LongColumnVector) col).vector[row]}; + return new byte[]{((ByteColumnVector) col).vector[row]}; case SHORT: case INT: + { + int value = col instanceof IntColumnVector ? + ((IntColumnVector) col).vector[row] : + (int) ((LongColumnVector) col).vector[row]; + return ByteBuffer.allocate(Integer.BYTES).putInt(value).array(); + } + case LONG: + return ByteBuffer.allocate(Long.BYTES).putLong(((LongColumnVector) col).vector[row]).array(); case DATE: + return ByteBuffer.allocate(Integer.BYTES).putInt(((DateColumnVector) col).dates[row]).array(); case TIME: - return ByteBuffer.allocate(Integer.BYTES).putInt((int) ((LongColumnVector) col).vector[row]).array(); - case LONG: + return ByteBuffer.allocate(Integer.BYTES).putInt(((TimeColumnVector) col).times[row]).array(); case TIMESTAMP: - return ByteBuffer.allocate(Long.BYTES).putLong(((LongColumnVector) col).vector[row]).array(); + return ByteBuffer.allocate(Long.BYTES).putLong(((TimestampColumnVector) col).times[row]).array(); case FLOAT: return ByteBuffer.allocate(Integer.BYTES).putInt(((FloatColumnVector) col).vector[row]).array(); case DOUBLE: @@ -1880,6 +1764,8 @@ public byte[] convertSqlStringToByte(String value) value = value.trim(); switch (getCategory()) { + case BYTE: + return new byte[]{Byte.parseByte(value)}; case BOOLEAN: { char c = value.charAt(0); diff --git a/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescription.java b/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescription.java new file mode 100644 index 0000000000..70c54bf825 --- /dev/null +++ b/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescription.java @@ -0,0 +1,242 @@ +/* + * Copyright 2026 PixelsDB. + * + * This file is part of Pixels. + * + * Pixels is free software: you can redistribute it and/or modify + * it under the terms of the Affero GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * Pixels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Affero GNU General Public License for more details. + * + * You should have received a copy of the Affero GNU General Public + * License along with Pixels. If not, see + * . + */ +package io.pixelsdb.pixels.core; + +import io.pixelsdb.pixels.core.vector.BinaryColumnVector; +import io.pixelsdb.pixels.core.vector.ByteColumnVector; +import io.pixelsdb.pixels.core.vector.ColumnVector; +import io.pixelsdb.pixels.core.vector.DateColumnVector; +import io.pixelsdb.pixels.core.vector.IntColumnVector; +import io.pixelsdb.pixels.core.vector.LongColumnVector; +import io.pixelsdb.pixels.core.vector.TimeColumnVector; +import io.pixelsdb.pixels.core.vector.TimestampColumnVector; +import org.junit.Test; + +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +/** + * Covers type-string parsing and single-cell byte conversion for {@link TypeDescription}. + */ +public class TestTypeDescription +{ + @Test + public void testParseDefaultsAndEntryPointsAgree() + { + assertEquals(TypeDescription.DEFAULT_VARCHAR_OR_BINARY_LENGTH, + parseBoth(" varchar ").getMaxLength()); + assertEquals(TypeDescription.DEFAULT_VARCHAR_OR_BINARY_LENGTH, + parseBoth("binary").getMaxLength()); + assertEquals(TypeDescription.DEFAULT_VARCHAR_OR_BINARY_LENGTH, + parseBoth("varbinary").getMaxLength()); + assertEquals(TypeDescription.DEFAULT_CHAR_LENGTH, + parseBoth("char").getMaxLength()); + assertEquals(TypeDescription.DEFAULT_TIME_PRECISION, + parseBoth("time").getPrecision()); + assertEquals(TypeDescription.DEFAULT_TIMESTAMP_PRECISION, + parseBoth("timestamp").getPrecision()); + + TypeDescription decimalP = parseBoth("decimal(12)"); + assertEquals(12, decimalP.getPrecision()); + assertEquals(TypeDescription.DEFAULT_DECIMAL_SCALE, decimalP.getScale()); + + TypeDescription decimalSpaced = parseBoth(" decimal ( 15 , 2 ) "); + assertEquals(15, decimalSpaced.getPrecision()); + assertEquals(2, decimalSpaced.getScale()); + + TypeDescription decimalDefault = parseBoth("decimal"); + assertEquals(TypeDescription.DEFAULT_LONG_DECIMAL_PRECISION, decimalDefault.getPrecision()); + assertEquals(TypeDescription.DEFAULT_DECIMAL_SCALE, decimalDefault.getScale()); + + assertNull(TypeDescription.fromString(null)); + } + + @Test + public void testParseTimePrecisionAndVectorAliases() + { + assertEquals(0, parseBoth("time(0)").getPrecision()); + assertEquals(1, parseBoth("time(1)").getPrecision()); + assertEquals(3, parseBoth("time(3)").getPrecision()); + assertEquals(6, parseBoth("timestamp(6)").getPrecision()); + assertIllegal("time(4)"); + assertIllegal("timestamp(7)"); + + TypeDescription vector = parseBoth("vector(128)"); + assertEquals(TypeDescription.Category.VECTOR, vector.getCategory()); + assertEquals(128, vector.getDimension()); + + TypeDescription array = parseBoth("array(double)"); + assertEquals(TypeDescription.Category.VECTOR, array.getCategory()); + assertEquals(TypeDescription.DEFAULT_VECTOR_DIMENSION, array.getDimension()); + + // Mixed struct must not confuse global contains("array") / contains("vector"). + TypeDescription mixed = parseBoth("struct"); + assertEquals(128, mixed.getChildren().get(0).getDimension()); + assertEquals(TypeDescription.DEFAULT_VECTOR_DIMENSION, + mixed.getChildren().get(1).getDimension()); + assertIllegal("array(128)"); + } + + @Test + public void testConvertSqlAndVectorAgree() + { + ByteColumnVector boolCol = new ByteColumnVector(2); + boolCol.vector[0] = 1; + boolCol.vector[1] = 0; + assertConvert(TypeDescription.createBoolean(), boolCol, 0, "true", new byte[]{1}); + assertConvert(TypeDescription.createBoolean(), boolCol, 1, "false", new byte[]{0}); + + ByteColumnVector byteCol = new ByteColumnVector(1); + byteCol.vector[0] = -12; + assertConvert(TypeDescription.createByte(), byteCol, 0, "-12", new byte[]{-12}); + + // SHORT/INT support both IntColumnVector and LongColumnVector modes. + IntColumnVector intMode = new IntColumnVector(1); + intMode.vector[0] = -1234; + assertConvert(TypeDescription.createShort(), intMode, 0, "-1234", + ByteBuffer.allocate(Integer.BYTES).putInt(-1234).array()); + assertConvert(TypeDescription.createInt(), intMode, 0, "-1234", + ByteBuffer.allocate(Integer.BYTES).putInt(-1234).array()); + + LongColumnVector longMode = new LongColumnVector(1); + longMode.vector[0] = 42; + assertConvert(TypeDescription.createShort(), longMode, 0, "42", + ByteBuffer.allocate(Integer.BYTES).putInt(42).array()); + assertConvert(TypeDescription.createInt(), longMode, 0, "42", + ByteBuffer.allocate(Integer.BYTES).putInt(42).array()); + + LongColumnVector longCol = new LongColumnVector(1); + longCol.vector[0] = Long.MAX_VALUE; + assertConvert(TypeDescription.createLong(), longCol, 0, String.valueOf(Long.MAX_VALUE), + ByteBuffer.allocate(Long.BYTES).putLong(Long.MAX_VALUE).array()); + + DateColumnVector dateCol = new DateColumnVector(1); + dateCol.dates[0] = 1; + assertConvert(TypeDescription.createDate(), dateCol, 0, "1970-01-02", + ByteBuffer.allocate(Integer.BYTES).putInt(1).array()); + + TimeColumnVector timeCol = new TimeColumnVector(1, 3); + timeCol.times[0] = 3723123; + assertConvert(TypeDescription.createTime(3), timeCol, 0, "01:02:03.123", + ByteBuffer.allocate(Integer.BYTES).putInt(3723123).array()); + + TimestampColumnVector tsCol = new TimestampColumnVector(1, 6); + tsCol.times[0] = 1234567L; + assertConvert(TypeDescription.createTimestamp(6), tsCol, 0, "1970-01-01 00:00:01.234567", + ByteBuffer.allocate(Long.BYTES).putLong(1234567L).array()); + + BinaryColumnVector binaryCol = new BinaryColumnVector(1); + byte[] payload = "hello".getBytes(); + binaryCol.setVal(0, payload); + assertConvert(TypeDescription.createVarchar(255), binaryCol, 0, "hello", payload); + } + + @Test + public void testConvertNullAndEmptySql() + { + ByteColumnVector col = new ByteColumnVector(1); + col.vector[0] = 42; + col.isNull[0] = true; + assertNull(TypeDescription.createByte().convertColumnVectorToByte(col, 0)); + + // Legacy PK text semantics retained in this PR. + assertNull(TypeDescription.createVarchar(16).convertSqlStringToByte(null)); + assertNull(TypeDescription.createVarchar(16).convertSqlStringToByte("")); + } + + private static TypeDescription parseBoth(String typeExpression) + { + TypeDescription fromString = TypeDescription.fromString(typeExpression); + TypeDescription fromSchema = TypeDescription.createSchemaFromStrings( + Collections.singletonList("column"), + Collections.singletonList(typeExpression)).getChildren().get(0); + assertEquivalent(fromString, fromSchema); + return fromString; + } + + private static void assertIllegal(String typeExpression) + { + try + { + TypeDescription.fromString(typeExpression); + fail("Expected invalid type expression: " + typeExpression); + } + catch (IllegalArgumentException expected) + { + // expected + } + + try + { + TypeDescription.createSchemaFromStrings( + Collections.singletonList("column"), + Collections.singletonList(typeExpression)); + fail("Expected invalid type expression: " + typeExpression); + } + catch (IllegalArgumentException expected) + { + // expected + } + } + + private static void assertConvert(TypeDescription type, ColumnVector col, int row, + String sqlValue, byte[] expected) + { + byte[] fromVector = type.convertColumnVectorToByte(col, row); + byte[] fromSql = type.convertSqlStringToByte(sqlValue); + assertArrayEquals(expected, fromVector); + assertArrayEquals(expected, fromSql); + } + + private static void assertEquivalent(TypeDescription expected, TypeDescription actual) + { + assertEquals(expected.getCategory(), actual.getCategory()); + assertEquals(expected.getMaxLength(), actual.getMaxLength()); + assertEquals(expected.getPrecision(), actual.getPrecision()); + assertEquals(expected.getScale(), actual.getScale()); + assertEquals(expected.getDimension(), actual.getDimension()); + + List expectedChildren = expected.getChildren(); + List actualChildren = actual.getChildren(); + if (expectedChildren == null) + { + assertNull(actualChildren); + return; + } + + assertNotNull(actualChildren); + assertEquals(expectedChildren.size(), actualChildren.size()); + if (expected.getCategory() == TypeDescription.Category.STRUCT) + { + assertEquals(expected.getFieldNames(), actual.getFieldNames()); + } + for (int i = 0; i < expectedChildren.size(); i++) + { + assertEquivalent(expectedChildren.get(i), actualChildren.get(i)); + } + } +} diff --git a/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescriptionConvert.java b/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescriptionConvert.java deleted file mode 100644 index b08e62665f..0000000000 --- a/pixels-core/src/test/java/io/pixelsdb/pixels/core/TestTypeDescriptionConvert.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2026 PixelsDB. - * - * This file is part of Pixels. - * - * Pixels is free software: you can redistribute it and/or modify - * it under the terms of the Affero GNU General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * Pixels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Affero GNU General Public License for more details. - * - * You should have received a copy of the Affero GNU General Public - * License along with Pixels. If not, see - * . - */ -package io.pixelsdb.pixels.core; - -import io.pixelsdb.pixels.core.vector.BinaryColumnVector; -import io.pixelsdb.pixels.core.vector.DecimalColumnVector; -import io.pixelsdb.pixels.core.vector.DoubleColumnVector; -import io.pixelsdb.pixels.core.vector.FloatColumnVector; -import io.pixelsdb.pixels.core.vector.LongColumnVector; -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Tests for {@link TypeDescription#convertColumnVectorToByte( - * io.pixelsdb.pixels.core.vector.ColumnVector, int)}. - * Migrated from TestStorageGarbageCollector where they were misplaced. - */ -public class TestTypeDescriptionConvert -{ - @Test - public void testConvertColumnVectorToByte_int() - { - LongColumnVector col = new LongColumnVector(2); - col.vector[0] = 42; - col.vector[1] = -1; - - byte[] bytes0 = TypeDescription.createInt().convertColumnVectorToByte(col, 0); - assertEquals(Integer.BYTES, bytes0.length); - assertEquals(42, ByteBuffer.wrap(bytes0).getInt()); - - byte[] bytes1 = TypeDescription.createInt().convertColumnVectorToByte(col, 1); - assertEquals(-1, ByteBuffer.wrap(bytes1).getInt()); - } - - @Test - public void testConvertColumnVectorToByte_long() - { - LongColumnVector col = new LongColumnVector(1); - col.vector[0] = Long.MAX_VALUE; - - byte[] bytes = TypeDescription.createLong().convertColumnVectorToByte(col, 0); - assertEquals(Long.BYTES, bytes.length); - assertEquals(Long.MAX_VALUE, ByteBuffer.wrap(bytes).getLong()); - } - - @Test - public void testConvertColumnVectorToByte_float() - { - FloatColumnVector col = new FloatColumnVector(1); - col.vector[0] = Float.floatToIntBits(3.14f); - - byte[] bytes = TypeDescription.createFloat().convertColumnVectorToByte(col, 0); - assertEquals(Integer.BYTES, bytes.length); - assertEquals(Float.floatToIntBits(3.14f), ByteBuffer.wrap(bytes).getInt()); - } - - @Test - public void testConvertColumnVectorToByte_double() - { - DoubleColumnVector col = new DoubleColumnVector(1); - col.vector[0] = Double.doubleToLongBits(2.718); - - byte[] bytes = TypeDescription.createDouble().convertColumnVectorToByte(col, 0); - assertEquals(Long.BYTES, bytes.length); - assertEquals(Double.doubleToLongBits(2.718), ByteBuffer.wrap(bytes).getLong()); - } - - @Test - public void testConvertColumnVectorToByte_string() - { - BinaryColumnVector col = new BinaryColumnVector(2); - byte[] hello = "hello".getBytes(); - byte[] world = "world!".getBytes(); - col.setVal(0, hello); - col.setVal(1, world); - - byte[] bytes0 = TypeDescription.createVarchar(255).convertColumnVectorToByte(col, 0); - assertTrue("string bytes must match", Arrays.equals(hello, bytes0)); - - byte[] bytes1 = TypeDescription.createString().convertColumnVectorToByte(col, 1); - assertTrue("string bytes must match", Arrays.equals(world, bytes1)); - } - - @Test - public void testConvertColumnVectorToByte_shortDecimal() - { - DecimalColumnVector col = new DecimalColumnVector(10, 2); - col.vector[0] = 12345L; - - TypeDescription decType = TypeDescription.createDecimal(10, 2); - byte[] bytes = decType.convertColumnVectorToByte(col, 0); - assertEquals(Long.BYTES, bytes.length); - assertEquals(12345L, ByteBuffer.wrap(bytes).getLong()); - } - - @Test - public void testConvertColumnVectorToByte_boolean() - { - LongColumnVector col = new LongColumnVector(2); - col.vector[0] = 1; - col.vector[1] = 0; - - byte[] bytes0 = TypeDescription.createBoolean().convertColumnVectorToByte(col, 0); - assertEquals(1, bytes0.length); - assertEquals(1, bytes0[0]); - - byte[] bytes1 = TypeDescription.createBoolean().convertColumnVectorToByte(col, 1); - assertEquals(1, bytes1.length); - assertEquals(0, bytes1[0]); - } -}