Skip to content

Commit 49d9ace

Browse files
committed
lint
1 parent 787bbcf commit 49d9ace

3 files changed

Lines changed: 79 additions & 42 deletions

File tree

parquet-hadoop/src/main/java/org/apache/parquet/hadoop/example/ValidatingUnsignedIntegerRecordConsumer.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public void startField(String field, int index) {
6363

6464
if (!types.isEmpty()) {
6565
Type parentType = types.peek();
66-
if (parentType.asGroupType() != null && index < parentType.asGroupType().getFieldCount()) {
66+
if (parentType.asGroupType() != null
67+
&& index < parentType.asGroupType().getFieldCount()) {
6768
Type fieldType = parentType.asGroupType().getType(index);
6869
types.push(fieldType);
6970
}
@@ -134,22 +135,21 @@ private void validateUnsignedInteger(int value) {
134135
switch (intType.getBitWidth()) {
135136
case 8:
136137
if (value < 0 || value > 255) {
137-
throw new InvalidRecordException(
138-
"Value " + value + " is out of range for UINT_8 (0-255) in field " + currentType.getName());
138+
throw new InvalidRecordException("Value " + value
139+
+ " is out of range for UINT_8 (0-255) in field " + currentType.getName());
139140
}
140141
break;
141142
case 16:
142143
if (value < 0 || value > 65535) {
143-
throw new InvalidRecordException(
144-
"Value " + value + " is out of range for UINT_16 (0-65535) in field " + currentType.getName());
144+
throw new InvalidRecordException("Value " + value
145+
+ " is out of range for UINT_16 (0-65535) in field " + currentType.getName());
145146
}
146147
break;
147148
case 32:
148149
case 64:
149150
if (value < 0) {
150-
throw new InvalidRecordException(
151-
"Negative value " + value + " is not allowed for unsigned integer type "
152-
+ currentType.getName());
151+
throw new InvalidRecordException("Negative value " + value
152+
+ " is not allowed for unsigned integer type " + currentType.getName());
153153
}
154154
break;
155155
}
@@ -167,9 +167,8 @@ private void validateUnsignedLong(long value) {
167167
(LogicalTypeAnnotation.IntLogicalTypeAnnotation) logicalType;
168168
if (!intType.isSigned()) {
169169
if (value < 0) {
170-
throw new InvalidRecordException(
171-
"Negative value " + value + " is not allowed for unsigned integer type "
172-
+ currentType.getName());
170+
throw new InvalidRecordException("Negative value " + value
171+
+ " is not allowed for unsigned integer type " + currentType.getName());
173172
}
174173
}
175174
}

parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestStrictUnsignedIntegerValidation.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.apache.parquet.schema.LogicalTypeAnnotation.intType;
2222
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32;
2323
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
24-
import static org.apache.parquet.schema.Types.required;
2524
import static org.junit.Assert.assertThrows;
2625

2726
import java.io.File;
@@ -48,10 +47,18 @@ public class TestStrictUnsignedIntegerValidation {
4847
@Test
4948
public void testValidUnsignedIntegerValues() throws IOException {
5049
MessageType schema = Types.buildMessage()
51-
.required(INT32).as(intType(8, false)).named("uint8_field")
52-
.required(INT32).as(intType(16, false)).named("uint16_field")
53-
.required(INT32).as(intType(32, false)).named("uint32_field")
54-
.required(INT64).as(intType(64, false)).named("uint64_field")
50+
.required(INT32)
51+
.as(intType(8, false))
52+
.named("uint8_field")
53+
.required(INT32)
54+
.as(intType(16, false))
55+
.named("uint16_field")
56+
.required(INT32)
57+
.as(intType(32, false))
58+
.named("uint32_field")
59+
.required(INT64)
60+
.as(intType(64, false))
61+
.named("uint64_field")
5562
.named("test_schema");
5663

5764
File tempFile = new File(tempFolder.getRoot(), "valid_unsigned.parquet");
@@ -64,15 +71,17 @@ public void testValidUnsignedIntegerValues() throws IOException {
6471

6572
SimpleGroupFactory groupFactory = new SimpleGroupFactory(schema);
6673

67-
Group validGroup = groupFactory.newGroup()
74+
Group validGroup = groupFactory
75+
.newGroup()
6876
.append("uint8_field", 255)
6977
.append("uint16_field", 65535)
7078
.append("uint32_field", Integer.MAX_VALUE)
7179
.append("uint64_field", Long.MAX_VALUE);
7280

7381
writer.write(validGroup);
7482

75-
Group zeroGroup = groupFactory.newGroup()
83+
Group zeroGroup = groupFactory
84+
.newGroup()
7685
.append("uint8_field", 0)
7786
.append("uint16_field", 0)
7887
.append("uint32_field", 0)
@@ -85,7 +94,9 @@ public void testValidUnsignedIntegerValues() throws IOException {
8594
@Test
8695
public void testInvalidUint8Values() throws IOException {
8796
MessageType schema = Types.buildMessage()
88-
.required(INT32).as(intType(8, false)).named("uint8_field")
97+
.required(INT32)
98+
.as(intType(8, false))
99+
.named("uint8_field")
89100
.named("test_schema");
90101

91102
File tempFile = new File(tempFolder.getRoot(), "invalid_uint8.parquet");
@@ -108,7 +119,9 @@ public void testInvalidUint8Values() throws IOException {
108119
@Test
109120
public void testInvalidUint16Values() throws IOException {
110121
MessageType schema = Types.buildMessage()
111-
.required(INT32).as(intType(16, false)).named("uint16_field")
122+
.required(INT32)
123+
.as(intType(16, false))
124+
.named("uint16_field")
112125
.named("test_schema");
113126

114127
File tempFile = new File(tempFolder.getRoot(), "invalid_uint16.parquet");
@@ -131,7 +144,9 @@ public void testInvalidUint16Values() throws IOException {
131144
@Test
132145
public void testInvalidUint32Values() throws IOException {
133146
MessageType schema = Types.buildMessage()
134-
.required(INT32).as(intType(32, false)).named("uint32_field")
147+
.required(INT32)
148+
.as(intType(32, false))
149+
.named("uint32_field")
135150
.named("test_schema");
136151

137152
File tempFile = new File(tempFolder.getRoot(), "invalid_uint32.parquet");
@@ -154,7 +169,9 @@ public void testInvalidUint32Values() throws IOException {
154169
@Test
155170
public void testInvalidUint64Values() throws IOException {
156171
MessageType schema = Types.buildMessage()
157-
.required(INT64).as(intType(64, false)).named("uint64_field")
172+
.required(INT64)
173+
.as(intType(64, false))
174+
.named("uint64_field")
158175
.named("test_schema");
159176

160177
File tempFile = new File(tempFolder.getRoot(), "invalid_uint64.parquet");
@@ -177,15 +194,16 @@ public void testInvalidUint64Values() throws IOException {
177194
@Test
178195
public void testValidationDisabledByDefault() throws IOException {
179196
MessageType schema = Types.buildMessage()
180-
.required(INT32).as(intType(8, false)).named("uint8_field")
197+
.required(INT32)
198+
.as(intType(8, false))
199+
.named("uint8_field")
181200
.named("test_schema");
182201

183202
File tempFile = new File(tempFolder.getRoot(), "validation_disabled.parquet");
184203
Path outputPath = new Path(tempFile.getAbsolutePath());
185204

186-
try (ParquetWriter<Group> writer = ExampleParquetWriter.builder(outputPath)
187-
.withType(schema)
188-
.build()) {
205+
try (ParquetWriter<Group> writer =
206+
ExampleParquetWriter.builder(outputPath).withType(schema).build()) {
189207

190208
SimpleGroupFactory groupFactory = new SimpleGroupFactory(schema);
191209

@@ -197,7 +215,9 @@ public void testValidationDisabledByDefault() throws IOException {
197215
@Test
198216
public void testValidationCanBeExplicitlyDisabled() throws IOException {
199217
MessageType schema = Types.buildMessage()
200-
.required(INT32).as(intType(8, false)).named("uint8_field")
218+
.required(INT32)
219+
.as(intType(8, false))
220+
.named("uint8_field")
201221
.named("test_schema");
202222

203223
File tempFile = new File(tempFolder.getRoot(), "validation_explicit_disabled.parquet");

parquet-hadoop/src/test/java/org/apache/parquet/hadoop/example/TestValidatingUnsignedIntegerRecordConsumer.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.FLOAT;
2424
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32;
2525
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
26-
import static org.apache.parquet.schema.Types.required;
2726
import static org.junit.Assert.assertThrows;
2827
import static org.mockito.Mockito.mock;
2928
import static org.mockito.Mockito.verify;
@@ -49,7 +48,9 @@ public void setUp() {
4948
@Test
5049
public void testValidUint8Values() {
5150
MessageType schema = Types.buildMessage()
52-
.required(INT32).as(intType(8, false)).named("uint8_field")
51+
.required(INT32)
52+
.as(intType(8, false))
53+
.named("uint8_field")
5354
.named("test_schema");
5455

5556
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -69,7 +70,9 @@ public void testValidUint8Values() {
6970
@Test
7071
public void testInvalidUint8Values() {
7172
MessageType schema = Types.buildMessage()
72-
.required(INT32).as(intType(8, false)).named("uint8_field")
73+
.required(INT32)
74+
.as(intType(8, false))
75+
.named("uint8_field")
7376
.named("test_schema");
7477

7578
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -89,7 +92,9 @@ public void testInvalidUint8Values() {
8992
@Test
9093
public void testValidUint16Values() {
9194
MessageType schema = Types.buildMessage()
92-
.required(INT32).as(intType(16, false)).named("uint16_field")
95+
.required(INT32)
96+
.as(intType(16, false))
97+
.named("uint16_field")
9398
.named("test_schema");
9499

95100
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -109,7 +114,9 @@ public void testValidUint16Values() {
109114
@Test
110115
public void testInvalidUint16Values() {
111116
MessageType schema = Types.buildMessage()
112-
.required(INT32).as(intType(16, false)).named("uint16_field")
117+
.required(INT32)
118+
.as(intType(16, false))
119+
.named("uint16_field")
113120
.named("test_schema");
114121

115122
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -129,7 +136,9 @@ public void testInvalidUint16Values() {
129136
@Test
130137
public void testValidUint32Values() {
131138
MessageType schema = Types.buildMessage()
132-
.required(INT32).as(intType(32, false)).named("uint32_field")
139+
.required(INT32)
140+
.as(intType(32, false))
141+
.named("uint32_field")
133142
.named("test_schema");
134143

135144
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -147,7 +156,9 @@ public void testValidUint32Values() {
147156
@Test
148157
public void testInvalidUint32Values() {
149158
MessageType schema = Types.buildMessage()
150-
.required(INT32).as(intType(32, false)).named("uint32_field")
159+
.required(INT32)
160+
.as(intType(32, false))
161+
.named("uint32_field")
151162
.named("test_schema");
152163

153164
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -163,7 +174,9 @@ public void testInvalidUint32Values() {
163174
@Test
164175
public void testValidUint64Values() {
165176
MessageType schema = Types.buildMessage()
166-
.required(INT64).as(intType(64, false)).named("uint64_field")
177+
.required(INT64)
178+
.as(intType(64, false))
179+
.named("uint64_field")
167180
.named("test_schema");
168181

169182
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -181,7 +194,9 @@ public void testValidUint64Values() {
181194
@Test
182195
public void testInvalidUint64Values() {
183196
MessageType schema = Types.buildMessage()
184-
.required(INT64).as(intType(64, false)).named("uint64_field")
197+
.required(INT64)
198+
.as(intType(64, false))
199+
.named("uint64_field")
185200
.named("test_schema");
186201

187202
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -197,7 +212,9 @@ public void testInvalidUint64Values() {
197212
@Test
198213
public void testSignedIntegerTypesNotValidated() {
199214
MessageType schema = Types.buildMessage()
200-
.required(INT32).as(intType(32, true)).named("signed_field")
215+
.required(INT32)
216+
.as(intType(32, true))
217+
.named("signed_field")
201218
.named("test_schema");
202219

203220
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -215,8 +232,10 @@ public void testSignedIntegerTypesNotValidated() {
215232
@Test
216233
public void testNonIntegerTypesIgnored() {
217234
MessageType schema = Types.buildMessage()
218-
.required(BINARY).named("binary_field")
219-
.required(FLOAT).named("float_field")
235+
.required(BINARY)
236+
.named("binary_field")
237+
.required(FLOAT)
238+
.named("float_field")
220239
.named("test_schema");
221240

222241
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
@@ -237,9 +256,8 @@ public void testNonIntegerTypesIgnored() {
237256

238257
@Test
239258
public void testAllRecordConsumerMethodsDelegated() {
240-
MessageType schema = Types.buildMessage()
241-
.required(INT32).named("test_field")
242-
.named("test_schema");
259+
MessageType schema =
260+
Types.buildMessage().required(INT32).named("test_field").named("test_schema");
243261

244262
validator = new ValidatingUnsignedIntegerRecordConsumer(mockDelegate, schema);
245263

0 commit comments

Comments
 (0)