PIG-5325: Schema disambiguation can't be turned off for nested schemas (szita)
git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1820631 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 7fc8a4a..87ed7b2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -64,6 +64,8 @@
BUG FIXES
+PIG-5325: Schema disambiguation can't be turned off for nested schemas (szita)
+
PIG-5311: POReservoirSample fails for more than Integer.MAX_VALUE records (rohini)
PIG-3864: ToDate(userstring, format, timezone) computes DateTime with strange handling of Daylight Saving Time with location based timezones (daijy via rohini)
diff --git a/src/org/apache/pig/newplan/logical/relational/LOStore.java b/src/org/apache/pig/newplan/logical/relational/LOStore.java
index 4e6fbf4..2b7c892 100644
--- a/src/org/apache/pig/newplan/logical/relational/LOStore.java
+++ b/src/org/apache/pig/newplan/logical/relational/LOStore.java
@@ -63,16 +63,31 @@
public LogicalSchema getSchema() throws FrontendException {
schema = ((LogicalRelationalOperator)plan.getPredecessors(this).get(0)).getSchema();
- if (!disambiguationEnabled && schema != null && schema.getFields() != null) {
+ if (!disambiguationEnabled) {
//If requested try and remove parent alias substring including colon(s)
+ removeDisambiguation(schema);
+ }
+
+ return schema;
+ }
+
+ /**
+ * Removes schema disambiguation parts (parent alias and :) from field aliases
+ * @param schema
+ * @return
+ */
+ private static LogicalSchema removeDisambiguation(LogicalSchema schema) {
+ if (schema != null && schema.getFields() != null) {
for (LogicalSchema.LogicalFieldSchema field : schema.getFields()) {
+ if (field.schema != null) {
+ removeDisambiguation(field.schema);
+ }
if (field.alias == null || !field.alias.contains(":")) {
continue;
}
field.alias = field.alias.substring(field.alias.lastIndexOf(":") + 1);
}
}
-
return schema;
}
diff --git a/test/org/apache/pig/test/TestSchema.java b/test/org/apache/pig/test/TestSchema.java
index d186797..62f7a1a 100644
--- a/test/org/apache/pig/test/TestSchema.java
+++ b/test/org/apache/pig/test/TestSchema.java
@@ -990,6 +990,33 @@
}
@Test
+ public void testDisabledDisambiguationContainsNoColonsForNestedSchema() throws IOException {
+ resetDisambiguationTestPropertyOverride();
+
+ String inputFileName = "testPrepend-nested-input.txt";
+ String[] inputData = new String[]{"apple\t1\tred", "orange\t2\torange", "kiwi\t3\tgreen", "orange\t4\torange"};
+ Util.createInputFile(cluster, inputFileName, inputData);
+
+ String script = "A = LOAD '" + inputFileName + "' AS (fruit:chararray, foo:int, color: chararray);" +
+ "B = LOAD '" + inputFileName + "' AS (id:chararray, bar:int);" +
+ "C = JOIN A by fruit, B by id;" +
+ "D = GROUP C by fruit;" +
+ "E = LOAD '" + inputFileName + "' AS (name:chararray, qwe:int);" +
+ "F = JOIN E by name, D by group;";
+
+ Util.registerMultiLineQuery(pigServer, script);
+
+ //Prepending should happen with default settings
+ assertEquals("{E::name: chararray,E::qwe: int,D::group: chararray,D::C: {(A::fruit: chararray,A::foo: int,A::color: chararray,B::id: chararray,B::bar: int)}}", pigServer.dumpSchema("F").toString());
+
+ //Override prepend property setting (check for flatten, join)
+ pigServer.getPigContext().getProperties().setProperty(PigConfiguration.PIG_STORE_SCHEMA_DISAMBIGUATE, "false");
+ assertEquals("{name: chararray,qwe: int,group: chararray,C: {(fruit: chararray,foo: int,color: chararray,id:" +
+ " chararray,bar: int)}}", pigServer.dumpSchema("F").toString());
+ assertTrue(pigServer.openIterator("F").hasNext());
+ }
+
+ @Test
public void testEnabledDisambiguationPassesForDupeAliases() throws IOException {
resetDisambiguationTestPropertyOverride();