private void checkRepresentation(String expression, int expectedSqlType, ResultAssertion assertion) throws Exception { try (ResultSet rs = statement.executeQuery("SELECT " + expression)) { ResultSetMetaData metadata = rs.getMetaData(); assertEquals(metadata.getColumnCount(), 1); assertEquals(metadata.getColumnType(1), expectedSqlType); assertTrue(rs.next()); assertion.accept(rs, 1); assertFalse(rs.next()); } }
public void testInvalidGetPartitionsByNames() { Map<String, Optional<Partition>> partitionsByNames = metastore.getPartitionsByNames(BAD_DATABASE, TEST_TABLE, ImmutableList.of(TEST_PARTITION1)); assertEquals(partitionsByNames.size(), 1); Optional<Partition> onlyElement = Iterables.getOnlyElement(partitionsByNames.values()); assertFalse(onlyElement.isPresent()); }
@Test public void testNonDeterministicScalarParse() { List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(NonDeterministicScalarFunction.class); assertEquals(functions.size(), 1); ParametricScalar scalar = (ParametricScalar) functions.get(0); assertFalse(scalar.isDeterministic()); assertFalse(scalar.isHidden()); }
@Test public void testBloomFilterPredicateValuesNonExisting() { BloomFilter bloomFilter = new BloomFilter(TEST_VALUES.size() * 10, 0.01); for (Map.Entry<Object, Type> testValue : TEST_VALUES.entrySet()) { boolean matched = checkInBloomFilter(bloomFilter, testValue.getKey(), testValue.getValue()); assertFalse(matched, "type " + testValue.getKey().getClass()); } // test unsupported type: can be supported by ORC but is not implemented yet assertTrue(checkInBloomFilter(bloomFilter, new Date(), DATE), "unsupported type DATE should always return true"); }
@Test public void testEmptyInput() { GroupedTopNBuilder groupedTopNBuilder = new GroupedTopNBuilder( ImmutableList.of(BIGINT), (left, leftPosition, right, rightPosition) -> { throw new UnsupportedOperationException(); }, 5, false, new NoChannelGroupByHash()); assertFalse(groupedTopNBuilder.buildResult().hasNext()); }
private void assertCallFails(@Language("SQL") String sql, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertFalse(tester.wasCalled()); assertEquals(e.getMessage(), message); } }
@Test public void testCatalog() { QualifiedTablePrefix tableName = new QualifiedTablePrefix("catalog"); assertEquals("catalog", tableName.getCatalogName()); assertFalse(tableName.hasSchemaName()); assertFalse(tableName.hasTableName()); }
@Test(description = "it should override an inherited model's name") public void overrideInheritedModelName() { final Map<String, Schema> rootSchemas = readAll(AbstractModelWithApiModel.class); assertEquals(rootSchemas.size(), 3); assertTrue(rootSchemas.containsKey("MyProperty")); assertTrue(rootSchemas.containsKey("ModelWithUrlProperty")); assertTrue(rootSchemas.containsKey("ModelWithValueProperty")); final Map<String, Schema> nestedSchemas = readAll(ModelWithUrlProperty.class); assertEquals(nestedSchemas.size(), 1); assertTrue(nestedSchemas.containsKey("ModelWithUrlProperty")); assertFalse(nestedSchemas.containsKey("MyProperties")); }
@Test public void testIsCompressionCodecSupported() { assertTrue(S3SelectPushdown.isCompressionCodecSupported(inputFormat, new Path("s3://fakeBucket/fakeObject.gz"))); assertTrue(S3SelectPushdown.isCompressionCodecSupported(inputFormat, new Path("s3://fakeBucket/fakeObject"))); assertFalse(S3SelectPushdown.isCompressionCodecSupported(inputFormat, new Path("s3://fakeBucket/fakeObject.lz4"))); assertFalse(S3SelectPushdown.isCompressionCodecSupported(inputFormat, new Path("s3://fakeBucket/fakeObject.snappy"))); assertTrue(S3SelectPushdown.isCompressionCodecSupported(inputFormat, new Path("s3://fakeBucket/fakeObject.bz2"))); } }
@Test(timeOut = 5000) public void testMergeSortedEmptyStreamsWithFinishedOnly() { List<ProcessState<Integer>> firstStream = ImmutableList.of( ProcessState.finished()); List<ProcessState<Integer>> secondStream = ImmutableList.of( ProcessState.finished()); WorkProcessor<Integer> mergedStream = WorkProcessorUtils.mergeSorted( ImmutableList.of(processorFrom(firstStream), processorFrom(secondStream)), Comparator.comparingInt(firstInteger -> firstInteger)); // before assertFalse(mergedStream.isBlocked()); assertFalse(mergedStream.isFinished()); assertFinishes(mergedStream); }
public void assertDecodedAs(String jsonValue, Type type, boolean expectedValue) { checkArgument(type.getJavaType() == boolean.class, "Wrong (not boolean based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getBoolean(), expectedValue); }
public static <T> void assertResult(WorkProcessor<T> processor, T result) { assertTrue(processor.process()); assertFalse(processor.isBlocked()); assertFalse(processor.isFinished()); assertEquals(processor.getResult(), result); }
@Test public void testIsOriginalOrder() { assertTrue(isOriginalOrder(ImmutableList.of(0, 1, 2, 3, 4))); assertFalse(isOriginalOrder(ImmutableList.of(0, 2, 1, 3, 4))); }
@Test public void testOverlaps() { AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertTrue(all.overlaps(all)); assertFalse(all.overlaps(none)); assertFalse(none.overlaps(all)); assertFalse(none.overlaps(none)); }
public void assertDecodedAs(String jsonValue, Type type, double expectedValue) { checkArgument(type.getJavaType() == double.class, "Wrong (not double based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getDouble(), expectedValue); }
@Test public void testIterator() { WorkProcessor<Integer> processor = processorFrom(ImmutableList.of( ProcessState.ofResult(1), ProcessState.ofResult(2), ProcessState.finished())); Iterator<Integer> iterator = processor.iterator(); assertTrue(iterator.hasNext()); assertEquals(iterator.next(), (Integer) 1); assertTrue(iterator.hasNext()); assertEquals(iterator.next(), (Integer) 2); assertFalse(iterator.hasNext()); }
@Test public void testIsS3FileSystem() { HdfsEnvironment hdfsEnvironment = createTestHdfsEnvironment(new HiveClientConfig()); assertTrue(isS3FileSystem(CONTEXT, hdfsEnvironment, new Path("s3://test-bucket/test-folder"))); assertFalse(isS3FileSystem(CONTEXT, hdfsEnvironment, new Path("/test-dir/test-folder"))); }
public void assertDecodedAs(String jsonValue, Type type, long expectedValue) { checkArgument(type.getJavaType() == long.class, "Wrong (not long based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getLong(), expectedValue); }
@Test public void testEmptyCursor() { ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(), ImmutableList.of(BIGINT, INTEGER)); assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, INTEGER)); RecordCursor cursor = recordSet.cursor(); assertFalse(cursor.advanceNextPosition()); }
@Test public void testStatsExtraction() throws Exception { try (PrestoResultSet rs = (PrestoResultSet) statement.executeQuery("SELECT 123 x, 456 x")) { assertNotNull(rs.getStats()); assertTrue(rs.next()); assertNotNull(rs.getStats()); assertFalse(rs.next()); assertNotNull(rs.getStats()); } }