@Test public void testOrdinaryInteger() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345, msgpackValue.asIntegerValue().asInt()); }
@Test public void testOrdinaryFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345.12"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); }
@Test public void testString() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("\"foobar\""); assertFalse(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isStringType()); assertEquals("foobar", msgpackValue.asStringValue().toString()); }
@Test public void testExponentialFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("1.234512E4"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); } }
@Test public void testExponentialInteger1() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345e3"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345000.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("1.2345E7", msgpackValue.asFloatValue().toString()); }
@Test public void testExponentialInteger2() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("123e2"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12300.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12300.0", msgpackValue.asFloatValue().toString()); }
if (!value.isMapValue()) { throw new JsonRecordValidateException( String.format("A Json record must not represent map value but it's %s", value.getValueType().name()));
private Object value(Value value) { switch (value.getValueType()) { case NIL: return null; case BOOLEAN: return value.asBooleanValue().getBoolean(); case INTEGER: return value.asIntegerValue().toLong(); case FLOAT: return value.asFloatValue().toFloat(); case STRING: return value.asStringValue().toString(); case BINARY: case ARRAY: case MAP: case EXTENSION: default: throw new UnsupportedOperationException("Unsupported column type: " + value.getValueType()); } } }
private Object doGuessDeserialize( ModuleDescriptor module, ValueType valueType, Value value ) throws IOException, ClassNotFoundException switch( value.getValueType() ) + " (" + value.getValueType() + ")" );
private boolean isTruthy(Value firstCol) { // Anything that is not NULL and not FALSE or 0 is considered truthy. switch (firstCol.getValueType()) { case NIL: return false; case BOOLEAN: return firstCol.asBooleanValue().getBoolean(); case INTEGER: return firstCol.asIntegerValue().asLong() != 0; default: return true; } } }
private boolean fetchJobResult(int rows, TDJobOperator job) { Optional<ArrayValue> firstRow = pollingRetryExecutor(state, RESULT) .retryUnless(TDOperator::isDeterministicClientException) .withErrorMessage("Failed to download result of job '%s'", job.getJobId()) .withRetryInterval(retryInterval) .run(s -> job.getResult( ite -> ite.hasNext() ? Optional.of(ite.next()) : Optional.absent())); if (!firstRow.isPresent()) { throw new TaskExecutionException("Got unexpected empty result for count job: " + job.getJobId()); } ArrayValue row = firstRow.get(); if (row.size() != 1) { throw new TaskExecutionException("Got unexpected result row size for count job: " + row.size()); } Value count = row.get(0); IntegerValue actualRows; try { actualRows = count.asIntegerValue(); } catch (MessageTypeCastException e) { throw new TaskExecutionException("Got unexpected value type count job: " + count.getValueType()); } return BigInteger.valueOf(rows).compareTo(actualRows.asBigInteger()) <= 0; }