forked from apache/iceberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORC: Add configurable write properties (apache#3810)
- Loading branch information
Showing
5 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
orc/src/test/java/org/apache/iceberg/orc/TestTableProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.iceberg.orc; | ||
|
||
import java.io.File; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.iceberg.FileFormat; | ||
import org.apache.iceberg.Files; | ||
import org.apache.iceberg.PartitionSpec; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.Table; | ||
import org.apache.iceberg.TableProperties; | ||
import org.apache.iceberg.common.DynFields; | ||
import org.apache.iceberg.data.Record; | ||
import org.apache.iceberg.data.orc.GenericOrcWriter; | ||
import org.apache.iceberg.deletes.EqualityDeleteWriter; | ||
import org.apache.iceberg.hadoop.HadoopTables; | ||
import org.apache.iceberg.io.FileAppender; | ||
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
import org.apache.iceberg.types.Types; | ||
import org.apache.orc.OrcConf; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class TestTableProperties { | ||
|
||
public static final Schema SCHEMA = new Schema( | ||
Types.NestedField.optional(1, "id", Types.IntegerType.get()), | ||
Types.NestedField.optional(2, "data", Types.StringType.get()) | ||
); | ||
|
||
@ClassRule | ||
public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); | ||
|
||
@Test | ||
public void testOrcTableProperties() throws Exception { | ||
Long stripeSizeBytes = 32L * 1024 * 1024; | ||
Long blockSizeBytes = 128L * 1024 * 1024; | ||
|
||
ImmutableMap<String, String> properties = ImmutableMap.of( | ||
TableProperties.ORC_STRIPE_SIZE_BYTES, String.valueOf(stripeSizeBytes), | ||
TableProperties.ORC_BLOCK_SIZE_BYTES, String.valueOf(blockSizeBytes), | ||
TableProperties.DEFAULT_FILE_FORMAT, FileFormat.ORC.name()); | ||
|
||
File folder = TEMPORARY_FOLDER.newFolder(); | ||
|
||
String warehouse = folder.getAbsolutePath(); | ||
String tablePath = warehouse.concat("/test"); | ||
Assert.assertTrue("Should create the table path correctly.", new File(tablePath).mkdir()); | ||
|
||
PartitionSpec spec = PartitionSpec.unpartitioned(); | ||
Table table = new HadoopTables().create(SCHEMA, spec, properties, tablePath); | ||
|
||
File testFile = TEMPORARY_FOLDER.newFile(); | ||
Assert.assertTrue(testFile.delete()); | ||
|
||
FileAppender<Record> writer = ORC.write(Files.localOutput(testFile)) | ||
.forTable(table) | ||
.createWriterFunc(GenericOrcWriter::buildWriter) | ||
.build(); | ||
|
||
DynFields.BoundField<Configuration> confField = | ||
DynFields.builder().hiddenImpl(writer.getClass(), "conf").build(writer); | ||
|
||
Configuration configuration = confField.get(); | ||
Assert.assertEquals(String.valueOf(blockSizeBytes), configuration.get(OrcConf.BLOCK_SIZE.getAttribute())); | ||
Assert.assertEquals(String.valueOf(stripeSizeBytes), configuration.get(OrcConf.STRIPE_SIZE.getAttribute())); | ||
Assert.assertEquals(FileFormat.ORC.name(), configuration.get(TableProperties.DEFAULT_FILE_FORMAT)); | ||
} | ||
|
||
@Test | ||
public void testOrcTableDeleteProperties() throws Exception { | ||
Long stripeSizeBytes = 32L * 1024 * 1024; | ||
Long blockSizeBytes = 128L * 1024 * 1024; | ||
|
||
ImmutableMap<String, String> properties = ImmutableMap.of( | ||
TableProperties.DELETE_ORC_STRIPE_SIZE_BYTES, String.valueOf(stripeSizeBytes), | ||
TableProperties.DELETE_ORC_BLOCK_SIZE_BYTES, String.valueOf(blockSizeBytes), | ||
TableProperties.DEFAULT_FILE_FORMAT, FileFormat.ORC.name()); | ||
|
||
File folder = TEMPORARY_FOLDER.newFolder(); | ||
|
||
String warehouse = folder.getAbsolutePath(); | ||
String tablePath = warehouse.concat("/test"); | ||
Assert.assertTrue("Should create the table path correctly.", new File(tablePath).mkdir()); | ||
|
||
PartitionSpec spec = PartitionSpec.unpartitioned(); | ||
Table table = new HadoopTables().create(SCHEMA, spec, properties, tablePath); | ||
|
||
File testFile = TEMPORARY_FOLDER.newFile(); | ||
Assert.assertTrue(testFile.delete()); | ||
|
||
EqualityDeleteWriter<Object> deleteWriter = ORC.writeDeletes(Files.localOutput(testFile)) | ||
.forTable(table) | ||
.equalityFieldIds(1) | ||
.createWriterFunc(GenericOrcWriter::buildWriter) | ||
.buildEqualityWriter(); | ||
|
||
DynFields.BoundField<OrcFileAppender<Record>> writer = | ||
DynFields.builder().hiddenImpl(deleteWriter.getClass(), "appender").build(deleteWriter); | ||
|
||
OrcFileAppender<Record> orcFileAppender = writer.get(); | ||
DynFields.BoundField<Configuration> confField = | ||
DynFields.builder().hiddenImpl(orcFileAppender.getClass(), "conf").build(orcFileAppender); | ||
|
||
Configuration configuration = confField.get(); | ||
Assert.assertEquals(String.valueOf(blockSizeBytes), configuration.get(OrcConf.BLOCK_SIZE.getAttribute())); | ||
Assert.assertEquals(String.valueOf(stripeSizeBytes), configuration.get(OrcConf.STRIPE_SIZE.getAttribute())); | ||
Assert.assertEquals(FileFormat.ORC.name(), configuration.get(TableProperties.DEFAULT_FILE_FORMAT)); | ||
} | ||
} |