Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT96;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -469,11 +470,13 @@ public void testRepeatedMap() throws IOException {
Assert.assertEquals("p, s<r<p>, r<p>>, r<s<r<s<p, p>>, p>>", toSummaryString(map));
}

@Test(expected = UnsupportedOperationException.class)
@Test
public void testArrowTimeSecondToParquet() {
converter
.fromArrow(new Schema(asList(field("a", new ArrowType.Time(TimeUnit.SECOND, 32)))))
.getParquetSchema();
assertThatThrownBy(() -> converter
.fromArrow(new Schema(asList(field("a", new ArrowType.Time(TimeUnit.SECOND, 32)))))
.getParquetSchema())
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Unsupported type Time(SECOND, 32)");
}

@Test
Expand Down Expand Up @@ -580,29 +583,35 @@ public void testParquetInt96ToArrowTimestamp() {
expected, converterInt96ToTimestamp.fromParquet(parquet).getArrowSchema());
}

@Test(expected = IllegalStateException.class)
@Test
public void testParquetInt64TimeMillisToArrow() {
converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT64)
.as(LogicalTypeAnnotation.timeType(false, MILLIS))
.named("a"))
.named("root"));
assertThatThrownBy(() -> converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT64)
.as(LogicalTypeAnnotation.timeType(false, MILLIS))
.named("a"))
.named("root")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("TIME(MILLIS,false) can only annotate INT32");
}

@Test(expected = IllegalStateException.class)
@Test
public void testParquetInt32TimeMicrosToArrow() {
converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timeType(false, MICROS))
.named("a"))
.named("root"));
assertThatThrownBy(() -> converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timeType(false, MICROS))
.named("a"))
.named("root")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("TIME(MICROS,false) can only annotate INT64");
}

@Test(expected = UnsupportedOperationException.class)
@Test
public void testArrowTimestampSecondToParquet() {
converter
.fromArrow(new Schema(asList(field("a", new ArrowType.Timestamp(TimeUnit.SECOND, "UTC")))))
.getParquetSchema();
assertThatThrownBy(() -> converter
.fromArrow(new Schema(asList(field("a", new ArrowType.Timestamp(TimeUnit.SECOND, "UTC")))))
.getParquetSchema())
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Unsupported type Timestamp(SECOND, UTC)");
}

@Test
Expand Down Expand Up @@ -655,21 +664,25 @@ public void testParquetInt64TimestampMicrosToArrow() {
Assert.assertEquals(expected, converter.fromParquet(parquet).getArrowSchema());
}

@Test(expected = IllegalStateException.class)
@Test
public void testParquetInt32TimestampMillisToArrow() {
converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timestampType(false, MILLIS))
.named("a"))
.named("root"));
assertThatThrownBy(() -> converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timestampType(false, MILLIS))
.named("a"))
.named("root")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("TIMESTAMP(MILLIS,false) can only annotate INT64");
}

@Test(expected = IllegalStateException.class)
@Test
public void testParquetInt32TimestampMicrosToArrow() {
converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timestampType(false, MICROS))
.named("a"))
.named("root"));
assertThatThrownBy(() -> converter.fromParquet(Types.buildMessage()
.addField(Types.optional(INT32)
.as(LogicalTypeAnnotation.timestampType(false, MICROS))
.named("a"))
.named("root")))
.isInstanceOf(IllegalStateException.class)
.hasMessage("TIMESTAMP(MICROS,false) can only annotate INT64");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT96;
import static org.apache.parquet.schema.Type.Repetition.REQUIRED;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.CALLS_REAL_METHODS;

Expand Down Expand Up @@ -168,9 +169,11 @@ private void testRoundTripConversion(Configuration conf, Schema avroSchema, Stri
convertedAvroSchema.toString());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testTopLevelMustBeARecord() {
new AvroSchemaConverter().convert(Schema.create(INT));
assertThatThrownBy(() -> new AvroSchemaConverter().convert(Schema.create(INT)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Avro schema must be a record.");
}

@Test
Expand Down Expand Up @@ -292,7 +295,7 @@ public void testAllTypesParquetToAvroOldBehavior() throws Exception {
testParquetToAvroConversion(schema, ALL_PARQUET_SCHEMA);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testParquetMapWithNonStringKeyFails() throws Exception {
MessageType parquetSchema =
MessageTypeParser.parseMessageType("message myrecord {\n" + " required group mymap (MAP) {\n"
Expand All @@ -302,7 +305,9 @@ public void testParquetMapWithNonStringKeyFails() throws Exception {
+ " }\n"
+ " }\n"
+ "}\n");
new AvroSchemaConverter().convert(parquetSchema);
assertThatThrownBy(() -> new AvroSchemaConverter().convert(parquetSchema))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Map key type must be binary (UTF8): required int32 key");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
import static org.apache.parquet.schema.Type.Repetition.REQUIRED;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand Down Expand Up @@ -256,7 +257,7 @@ public void testMapWithNulls() throws Exception {
}
}

@Test(expected = RuntimeException.class)
@Test
public void testMapRequiredValueWithNull() throws Exception {
Schema schema = Schema.createRecord("record1", null, null, false);
schema.setFields(Lists.newArrayList(
Expand All @@ -277,7 +278,9 @@ public void testMapRequiredValueWithNull() throws Exception {

GenericData.Record record =
new GenericRecordBuilder(schema).set("mymap", map).build();
writer.write(record);
assertThatThrownBy(() -> writer.write(record))
.isInstanceOf(RuntimeException.class)
.hasMessage("Null map value for map");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.parquet.avro.AvroTestUtil.optionalField;
import static org.apache.parquet.avro.AvroTestUtil.primitive;
import static org.apache.parquet.avro.AvroTestUtil.record;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -161,7 +162,7 @@ public void testMapWithNulls() throws Exception {
}
}

@Test(expected = RuntimeException.class)
@Test
public void testMapRequiredValueWithNull() throws Exception {
Schema schema = Schema.createRecord("record1", null, null, false);
schema.setFields(Lists.newArrayList(
Expand All @@ -181,7 +182,9 @@ public void testMapRequiredValueWithNull() throws Exception {

GenericData.Record record =
new GenericRecordBuilder(schema).set("mymap", map).build();
writer.write(record);
assertThatThrownBy(() -> writer.write(record))
.isInstanceOf(RuntimeException.class)
.hasMessage("Null map value for map");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.parquet.avro;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
Expand Down Expand Up @@ -349,7 +351,7 @@ public void testReflectJavaClass() throws IOException {
Assert.assertEquals("Should have the correct BigDecimal value", BIG_DECIMAL, parquetRecord.stringable_class);
}

@Test(expected = SecurityException.class)
@Test
public void testSpecificValidationFail() throws IOException {
Configuration conf = new Configuration();
conf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, false);
Expand All @@ -359,11 +361,16 @@ public void testSpecificValidationFail() throws IOException {
AvroParquetReader.<org.apache.parquet.avro.StringBehaviorTest>builder(parquetFile)
.withConf(conf)
.build()) {
parquet.read();
assertThatThrownBy(parquet::read)
.isInstanceOf(SecurityException.class)
.hasMessage(
"Forbidden java.math.BigDecimal! This class is not trusted to be included in Avro schema "
+ "using java-class or java-key-class. Please set the Parquet/Hadoop configuration "
+ "parquet.avro.serializable.classes with the classes you trust.");
}
}

@Test(expected = SecurityException.class)
@Test
public void testReflectValidationFail() throws IOException {
Schema reflectSchema = ReflectData.get().getSchema(ReflectRecord.class);

Expand All @@ -374,11 +381,16 @@ public void testReflectValidationFail() throws IOException {
try (ParquetReader<ReflectRecord> parquet = AvroParquetReader.<ReflectRecord>builder(parquetFile)
.withConf(conf)
.build()) {
parquet.read();
assertThatThrownBy(parquet::read)
.isInstanceOf(SecurityException.class)
.hasMessage(
"Forbidden java.math.BigDecimal! This class is not trusted to be included in Avro schema "
+ "using java-class or java-key-class. Please set the Parquet/Hadoop configuration "
+ "parquet.avro.serializable.classes with the classes you trust.");
}
}

@Test(expected = SecurityException.class)
@Test
public void testReflectJavaClassValidationFail() throws IOException {
Schema reflectSchema = ReflectData.get().getSchema(ReflectRecordJavaClass.class);

Expand All @@ -391,7 +403,12 @@ public void testReflectJavaClassValidationFail() throws IOException {
parquetFile)
.withConf(conf)
.build()) {
parquet.read();
assertThatThrownBy(parquet::read)
.isInstanceOf(SecurityException.class)
.hasMessage(
"Forbidden java.math.BigDecimal! This class is not trusted to be included in Avro schema "
+ "using java-class or java-key-class. Please set the Parquet/Hadoop configuration "
+ "parquet.avro.serializable.classes with the classes you trust.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.protobuf.Message;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -65,14 +67,16 @@ public void testCatCommandWithSpecificColumns() throws IOException {
Assert.assertEquals(0, command.run());
}

@Test(expected = IllegalArgumentException.class)
public void testCatCommandWithInvalidColumn() throws IOException {
@Test
public void testCatCommandWithInvalidColumn() {
File file = parquetFile();
CatCommand command = new CatCommand(createLogger(), 0);
command.sourceFiles = Arrays.asList(file.getAbsolutePath());
command.columns = Arrays.asList("invalid_field");
command.setConf(new Configuration());
command.run();
assertThatThrownBy(command::run)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Cannot find field 'invalid_field' in schema");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -50,16 +52,18 @@ public void testConvertCSVCommandWithMultipleInput() throws IOException {
Assert.assertTrue(output.exists());
}

@Test(expected = IllegalArgumentException.class)
public void testConvertCSVCommandWithDifferentSchemas() throws IOException {
@Test
public void testConvertCSVCommandWithDifferentSchemas() {
File file = csvFile();
File fileWithDifferentSchema = csvFileWithDifferentSchema();
ConvertCSVCommand command = new ConvertCSVCommand(createLogger());
command.targets = Arrays.asList(file.getAbsolutePath(), fileWithDifferentSchema.getAbsolutePath());
File output = new File(getTempFolder(), getClass().getSimpleName() + ".parquet");
command.outputPath = output.getAbsolutePath();
command.setConf(new Configuration());
command.run();
assertThatThrownBy(command::run)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("seems to have a different schema from others");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.parquet.cli.commands;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -40,7 +42,7 @@ public void testRewriteCommand() throws IOException {
Assert.assertTrue(output.exists());
}

@Test(expected = FileAlreadyExistsException.class)
@Test
public void testRewriteCommandWithoutOverwrite() throws IOException {
File file = parquetFile();
RewriteCommand command = new RewriteCommand(createLogger());
Expand All @@ -50,7 +52,9 @@ public void testRewriteCommandWithoutOverwrite() throws IOException {
command.setConf(new Configuration());

Files.createFile(output.toPath());
command.run();
assertThatThrownBy(command::run)
.isInstanceOf(FileAlreadyExistsException.class)
.hasMessageContaining("File already exists");
}

@Test
Expand Down
Loading
Loading