private void assertUnsupportedColumnTypeException(ThrowableAssert.ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("Unsupported column type .* for column .*"); }
private void assertWrongDataFormatException(ThrowableAssert.ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("Wrong dataFormat .* specified for column .*"); }
private void assertRuntimeDecodingFailure(ThrowableAssert.ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("could not parse value .* as .* for column .*"); } }
private void assertUnsupportedColumnTypeException(ThrowableAssert.ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("Unsupported column type .* for column .*"); }
private void assertUnsupportedColumnTypeException(ThrowableAssert.ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("Unsupported column type .* for column .*"); }
private void assertUnsupportedColumnTypeException(ThrowingCallable callable) { assertThatThrownBy(callable) .isInstanceOf(PrestoException.class) .hasMessageMatching("unsupported column type .* for column .*"); }
@Test public void testInvalidDataFormat() { assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", "format", null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("invalid dataFormat 'format' for column 'some_column'"); }
private static void assertFails(String fileName, String expectedPattern) { assertThatThrownBy(() -> parse(fileName)).hasMessageMatching(expectedPattern); } }
@Test public void testInvalidExtraneousParameters() { assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "mapping", null, "hint", false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected format hint 'hint' defined for column 'some_column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "mapping", null, null, false, false, true)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected internal column 'some_column'"); }
@Test public void testInvalidExtraneousParameters() { assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, "hint", false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected format hint 'hint' defined for column 'some_column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, null, false, false, true)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected internal column 'some_column'"); }
@Test public void testInvalidExtraneousParameters() { assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", "format", null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected data format 'format' defined for column 'column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, "hint", false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected format hint 'hint' defined for column 'column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, null, false, false, true)) .isInstanceOf(PrestoException.class) .hasMessageMatching("unexpected internal column 'column'"); }
@Test public void testWrongMappingDefined() { assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, null, null, null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("mapping not defined for column 'column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "x", null, null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("invalid mapping 'x' for column 'column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "-1", null, null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("invalid mapping '-1' for column 'column'"); assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "1:1", null, null, false, false, false)) .isInstanceOf(PrestoException.class) .hasMessageMatching("invalid mapping '1:1' for column 'column'"); }
@Test public void testRuntimeDecodingFailure() { DecoderTestColumnHandle booleanColumn = new DecoderTestColumnHandle(0, "some_column", BOOLEAN, "long_field", null, null, false, false, false); Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(booleanColumn, "long_field", "\"long\"", (long) 1); assertThatThrownBy(decodedRow.get(booleanColumn)::getBoolean) .isInstanceOf(PrestoException.class) .hasMessageMatching("cannot decode object of 'class java.lang.Long' as 'boolean' for column 'some_column'"); }
public void assertInvalidInput(String jsonValue, Type type, String exceptionRegex) { assertThatThrownBy(() -> decode(Optional.of(jsonValue), type).getLong()) .isInstanceOf(PrestoException.class) .hasMessageMatching(exceptionRegex); }
@Test public void checkCastShouldThrowExceptionWhenTargetObjectCanNotBeTypeCasted() { assertThatThrownBy(() -> TypeUtils.checkCast("SomeCharacters", Integer.class)) .isInstanceOf(InternalGemFireError.class) .hasMessageMatching("^expected instance of (.*) but was (.*)$"); }
@Test public void testSchemaEvolutionToIncompatibleType() throws Exception { byte[] originalIntData = buildAvroData(new Schema.Parser().parse( getAvroSchema("int_to_string_field", "\"int\"")), "int_to_string_field", 100); DecoderTestColumnHandle stringColumnReadingIntData = new DecoderTestColumnHandle(0, "row0", VARCHAR, "int_to_string_field", null, null, false, false, false); String changedTypeSchema = getAvroSchema("int_to_string_field", "\"string\""); assertThatThrownBy(() -> decodeRow(originalIntData, ImmutableSet.of(stringColumnReadingIntData), ImmutableMap.of(DATA_SCHEMA, changedTypeSchema))) .isInstanceOf(PrestoException.class) .hasCauseExactlyInstanceOf(AvroTypeException.class) .hasStackTraceContaining("Found int, expecting string") .hasMessageMatching("Decoding Avro record failed."); }
@Test public void testInvalidFormatHint() { DecoderTestColumnHandle columnHandle = new DecoderTestColumnHandle( 0, "some_column", TIMESTAMP, "mappedField", "custom-date-time", "XXMM/yyyy/dd H:m:sXX", false, false, false); assertThatThrownBy(() -> new JsonRowDecoderFactory(new ObjectMapperProvider().get()).create(emptyMap(), ImmutableSet.of(columnHandle))) .isInstanceOf(PrestoException.class) .hasMessageMatching("invalid joda pattern 'XXMM/yyyy/dd H:m:sXX' passed as format hint for column 'some_column'"); } }
private void doInsertUnsupportedWriteType(HiveStorageFormat storageFormat, SchemaTableName tableName) throws Exception { List<Column> columns = ImmutableList.of(new Column("dummy", HiveType.valueOf("uniontype<smallint,tinyint>"), Optional.empty())); List<Column> partitionColumns = ImmutableList.of(new Column("name", HIVE_STRING, Optional.empty())); createEmptyTable(tableName, storageFormat, columns, partitionColumns); try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorSession session = newSession(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName); metadata.beginInsert(session, tableHandle); fail("expected failure"); } catch (PrestoException e) { assertThat(e).hasMessageMatching("Inserting into Hive table .* with column type uniontype<smallint,tinyint> not supported"); } }
@Test public void testGetPartitionSplitsTableNotReadablePartition() { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorSession session = newSession(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableNotReadable); assertNotNull(tableHandle); ColumnHandle dsColumn = metadata.getColumnHandles(session, tableHandle).get("ds"); assertNotNull(dsColumn); List<ConnectorTableLayoutResult> tableLayoutResults = metadata.getTableLayouts(session, tableHandle, Constraint.alwaysTrue(), Optional.empty()); try { getSplitCount(splitManager.getSplits(transaction.getTransactionHandle(), session, getOnlyElement(tableLayoutResults).getTableLayout().getHandle(), UNGROUPED_SCHEDULING)); fail("Expected HiveNotReadableException"); } catch (HiveNotReadableException e) { assertThat(e).hasMessageMatching("Table '.*\\.presto_test_not_readable' is not readable: reason for not readable"); assertEquals(e.getTableName(), tableNotReadable); assertEquals(e.getPartition(), Optional.empty()); } } }
@Test(groups = {HIVE_PARTITIONING}) public void testShowPartitionsFromHiveTableWithTooManyPartitions() { String tableName = tablesState.get(PARTITIONED_TABLE_WITH_VARIABLE_PARTITIONS).getNameInDatabase(); String partitionsTable = "\"" + tableName + "$partitions\""; createPartitions(tableName, TOO_MANY_PARTITIONS); // Verify we created enough partitions for the test to be meaningful assertThatThrownBy(() -> query("SELECT * FROM " + tableName)) .hasMessageMatching(".*: Query over table '\\S+' can potentially read more than \\d+ partitions"); QueryResult partitionListResult; partitionListResult = query(format("SELECT * FROM %s WHERE part_col < 7", partitionsTable)); assertThat(partitionListResult).containsExactly(row(0), row(1), row(2), row(3), row(4), row(5), row(6)); assertColumnNames(partitionListResult, "part_col"); partitionListResult = query(format("SELECT * FROM %s WHERE part_col < -10", partitionsTable)); assertThat(partitionListResult).hasNoRows(); partitionListResult = query(format("SELECT * FROM %s ORDER BY part_col LIMIT 7", partitionsTable)); assertThat(partitionListResult).containsExactly(row(0), row(1), row(2), row(3), row(4), row(5), row(6)); }