You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by pg...@apache.org on 2020/12/01 09:25:00 UTC
[orc] branch branch-1.6 updated: ORC-688: Allow CHAR to be promoted
to STRING (#575)
This is an automated email from the ASF dual-hosted git repository.
pgaref pushed a commit to branch branch-1.6
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-1.6 by this push:
new fb18bbb ORC-688: Allow CHAR to be promoted to STRING (#575)
fb18bbb is described below
commit fb18bbb02c08b8a0da5ad811210102cf7b421096
Author: Panagiotis Garefalakis <pg...@apache.org>
AuthorDate: Tue Dec 1 09:24:51 2020 +0000
ORC-688: Allow CHAR to be promoted to STRING (#575)
### What changes were proposed in this pull request?
Enable String conversion from varchar.
Currently createStringConvertTreeReader in ConvertTreeReaderFactory is missing that opportunity
### Why are the changes needed?
Modify createStringConvertTreeReader to handle char, varchar and string as part of the same group.
### How was this patch tested?
TestSchemaEvolution.testCharToStringEvolution
(cherry picked from commit 48cba3bafa7ef31f162f8c377d513f1c58a27876)
Change-Id: Ibf1daa60665784c21dc7d25066d85e1b7193b155
---
.../apache/orc/impl/ConvertTreeReaderFactory.java | 7 +----
.../org/apache/orc/impl/TestSchemaEvolution.java | 32 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
index 6a8682d..bd6bac5 100644
--- a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
@@ -1914,14 +1914,9 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new DecimalFromStringGroupTreeReader(columnId, fileType, readerType, context);
case CHAR:
- return new StringGroupFromStringGroupTreeReader(columnId, fileType, readerType, context);
-
case VARCHAR:
- return new StringGroupFromStringGroupTreeReader(columnId, fileType, readerType, context);
-
case STRING:
- throw new IllegalArgumentException("No conversion of type " +
- readerType.getCategory() + " to self needed");
+ return new StringGroupFromStringGroupTreeReader(columnId, fileType, readerType, context);
case BINARY:
return new BinaryTreeReader(columnId, context);
diff --git a/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java b/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
index af30854..94c3b25 100644
--- a/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
+++ b/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
@@ -577,6 +577,38 @@ public class TestSchemaEvolution {
}
@Test
+ public void testCharToStringEvolution() throws IOException {
+ TypeDescription fileType = TypeDescription.fromString("struct<x:char(10)>");
+ TypeDescription readType = TypeDescription.fromString("struct<x:string>");
+ SchemaEvolution evo = new SchemaEvolution(fileType, readType, options);
+
+ TreeReaderFactory.Context treeContext =
+ new TreeReaderFactory.ReaderContext().setSchemaEvolution(evo);
+ TreeReaderFactory.TreeReader reader =
+ TreeReaderFactory.createTreeReader(readType, treeContext);
+
+ // Make sure the tree reader is built properly
+ assertEquals(TreeReaderFactory.StructTreeReader.class, reader.getClass());
+ TreeReaderFactory.TreeReader[] children =
+ ((TreeReaderFactory.StructTreeReader) reader).getChildReaders();
+ assertEquals(1, children.length);
+ assertEquals(ConvertTreeReaderFactory.StringGroupFromStringGroupTreeReader.class, children[0].getClass());
+
+ // Make sure that varchar behaves the same as char
+ fileType = TypeDescription.fromString("struct<x:varchar(10)>");
+ evo = new SchemaEvolution(fileType, readType, options);
+
+ treeContext = new TreeReaderFactory.ReaderContext().setSchemaEvolution(evo);
+ reader = TreeReaderFactory.createTreeReader(readType, treeContext);
+
+ // Make sure the tree reader is built properly
+ assertEquals(TreeReaderFactory.StructTreeReader.class, reader.getClass());
+ children = ((TreeReaderFactory.StructTreeReader) reader).getChildReaders();
+ assertEquals(1, children.length);
+ assertEquals(ConvertTreeReaderFactory.StringGroupFromStringGroupTreeReader.class, children[0].getClass());
+ }
+
+ @Test
public void testStringToDecimalEvolution() throws Exception {
testFilePath = new Path(workDir, "TestSchemaEvolution." +
testCaseName.getMethodName() + ".orc");