Java Code Examples for org.apache.arrow.vector.IntVector#clear()
The following examples show how to use
org.apache.arrow.vector.IntVector#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntToFixedConverterTest.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
@Test public void testInvalidConversion() { // try convert to int/long/byte/short with scale > 0 Map<String, String> customFieldMeta = new HashMap<>(); customFieldMeta.put("logicalType", "FIXED"); customFieldMeta.put("precision", "10"); customFieldMeta.put("scale", "3"); FieldType fieldType = new FieldType(true, Types.MinorType.INT.getType(), null, customFieldMeta); IntVector vector = new IntVector("col_one", fieldType, allocator); vector.setSafe(0, 33000); final ArrowVectorConverter converter = new IntToScaledFixedConverter(vector, 0, this, 3); final int invalidConversionErrorCode = ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toBoolean(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toLong(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toInt(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toShort(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toByte(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toDate(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toTime(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toTimestamp(0, TimeZone.getDefault())); vector.clear(); }
Example 2
Source File: IntToFixedConverterTest.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
@Test public void testFixedNoScale() throws SFException { final int rowCount = 1000; List<Integer> expectedValues = new ArrayList<>(); Set<Integer> nullValIndex = new HashSet<>(); for (int i = 0; i < rowCount; i++) { expectedValues.add(random.nextInt()); } Map<String, String> customFieldMeta = new HashMap<>(); customFieldMeta.put("logicalType", "FIXED"); customFieldMeta.put("precision", "10"); customFieldMeta.put("scale", "0"); FieldType fieldType = new FieldType(true, Types.MinorType.INT.getType(), null, customFieldMeta); IntVector vector = new IntVector("col_one", fieldType, allocator); for (int i = 0; i < rowCount; i++) { boolean isNull = random.nextBoolean(); if (isNull) { vector.setNull(i); nullValIndex.add(i); } else { vector.setSafe(i, expectedValues.get(i)); } } ArrowVectorConverter converter = new IntToFixedConverter(vector, 0, this); for (int i = 0; i < rowCount; i++) { int intVal = converter.toInt(i); Object longObj = converter.toObject(i); String intString = converter.toString(i); if (nullValIndex.contains(i)) { assertThat(intVal, is(0)); assertThat(longObj, is(nullValue())); assertThat(intString, is(nullValue())); assertThat(converter.toBytes(i), is(nullValue())); } else { assertThat(intVal, is(expectedValues.get(i))); assertEquals(longObj, (long) expectedValues.get(i)); assertThat(intString, is(expectedValues.get(i).toString())); bb = ByteBuffer.wrap(converter.toBytes(i)); assertThat(intVal, is(bb.getInt())); } } vector.clear(); }
Example 3
Source File: IntToFixedConverterTest.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
@Test public void testFixedWithScale() throws SFException { final int rowCount = 1000; List<Integer> expectedValues = new ArrayList<>(); Set<Integer> nullValIndex = new HashSet<>(); for (int i = 0; i < rowCount; i++) { expectedValues.add(random.nextInt()); } Map<String, String> customFieldMeta = new HashMap<>(); customFieldMeta.put("logicalType", "FIXED"); customFieldMeta.put("precision", "10"); customFieldMeta.put("scale", "3"); FieldType fieldType = new FieldType(true, Types.MinorType.INT.getType(), null, customFieldMeta); IntVector vector = new IntVector("col_one", fieldType, allocator); for (int i = 0; i < rowCount; i++) { boolean isNull = random.nextBoolean(); if (isNull) { vector.setNull(i); nullValIndex.add(i); } else { vector.setSafe(i, expectedValues.get(i)); } } ArrowVectorConverter converter = new IntToScaledFixedConverter(vector, 0, this, 3); for (int i = 0; i < rowCount; i++) { BigDecimal bigDecimalVal = converter.toBigDecimal(i); Object objectVal = converter.toObject(i); String stringVal = converter.toString(i); if (nullValIndex.contains(i)) { assertThat(bigDecimalVal, nullValue()); assertThat(objectVal, nullValue()); assertThat(stringVal, nullValue()); assertThat(converter.toBytes(i), is(nullValue())); } else { BigDecimal expectedVal = BigDecimal.valueOf(expectedValues.get(i), 3); assertThat(bigDecimalVal, is(expectedVal)); assertThat(objectVal, is(expectedVal)); assertThat(stringVal, is(expectedVal.toString())); assertThat(converter.toBytes(i), is(notNullValue())); } } vector.clear(); }
Example 4
Source File: IntToFixedConverterTest.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
@Test public void testGetSmallerIntegralType() throws SFException { // try convert to int/long/byte/short with scale > 0 Map<String, String> customFieldMeta = new HashMap<>(); customFieldMeta.put("logicalType", "FIXED"); customFieldMeta.put("precision", "10"); customFieldMeta.put("scale", "0"); FieldType fieldType = new FieldType(true, Types.MinorType.INT.getType(), null, customFieldMeta); // test value which is out of range of int, but falls in long IntVector vectorFoo = new IntVector("col_one", fieldType, allocator); vectorFoo.setSafe(0, 33000); vectorFoo.setSafe(1, -33000); final ArrowVectorConverter converterFoo = new IntToFixedConverter(vectorFoo, 0, this); final int invalidConversionErrorCode = ErrorCode.INVALID_VALUE_CONVERT.getMessageCode(); TestUtil.assertSFException(invalidConversionErrorCode, () -> converterFoo.toShort(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converterFoo.toByte(0)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converterFoo.toShort(1)); TestUtil.assertSFException(invalidConversionErrorCode, () -> converterFoo.toByte(1)); assertThat(converterFoo.toLong(0), is(33000L)); assertThat(converterFoo.toLong(1), is(-33000L)); vectorFoo.clear(); // test value which is in range of byte, all get method should return IntVector vectorBar = new IntVector("col_one", fieldType, allocator); // set value which is out of range of int, but falls in long vectorBar.setSafe(0, 10); vectorBar.setSafe(1, -10); final ArrowVectorConverter converterBar = new IntToFixedConverter(vectorBar, 0, this); assertThat(converterBar.toByte(0), is((byte) 10)); assertThat(converterBar.toByte(1), is((byte) -10)); assertThat(converterBar.toShort(0), is((short) 10)); assertThat(converterBar.toShort(1), is((short) -10)); assertThat(converterBar.toLong(0), is(10L)); assertThat(converterBar.toLong(1), is(-10L)); vectorBar.clear(); }
Example 5
Source File: IntToTimeConverterTest.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
@Test public void testTime() throws SFException { // test old and new dates int[] testTimesInt = { 12345678 }; String[] testTimesJson = { "12345.678" }; Time[] expectedTimes = { new Time(12345678) }; Map<String, String> customFieldMeta = new HashMap<>(); customFieldMeta.put("logicalType", "TIME"); Set<Integer> nullValIndex = new HashSet<>(); // test normal date FieldType fieldType = new FieldType(true, Types.MinorType.INT.getType(), null, customFieldMeta); IntVector vector = new IntVector("date", fieldType, allocator); int i = 0, j = 0; while (i < testTimesInt.length) { boolean isNull = random.nextBoolean(); if (isNull) { vector.setNull(j); nullValIndex.add(j); } else { vector.setSafe(j, testTimesInt[i++]); } j++; } ArrowVectorConverter converter = new IntToTimeConverter(vector, 0, this); int rowCount = j; i = 0; j = 0; while (j < rowCount) { String strVal = converter.toString(j); Time time = converter.toTime(j); Object obj = converter.toObject(j); Time oldTime = new Time(ResultUtil.getSFTime( testTimesJson[i], scale, new SFSession()).getFractionalSeconds( ResultUtil.DEFAULT_SCALE_OF_SFTIME_FRACTION_SECONDS)); if (nullValIndex.contains(j)) { assertThat(obj, is(nullValue())); assertThat(strVal, is(nullValue())); assertThat(false, is(converter.toBoolean(j))); assertThat(converter.toBytes(j), is(nullValue())); assertThat(0, is(converter.toInt(j))); } else { assertThat(expectedTimes[i], is(time)); assertThat(expectedTimes[i], is((Time) obj)); assertThat(oldTime, is(time)); assertThat(oldTime, is((Time) obj)); final int x = j; TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toBoolean(x)); assertThat(converter.toBytes(j), is(notNullValue())); } j++; } vector.clear(); }