[ 
https://issues.apache.org/jira/browse/GOBBLIN-957?focusedWorklogId=343752&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-343752
 ]

ASF GitHub Bot logged work on GOBBLIN-957:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Nov/19 21:17
            Start Date: 14/Nov/19 21:17
    Worklog Time Spent: 10m 
      Work Description: shirshanka commented on pull request #2806: 
GOBBLIN-957: Add recursion eliminating converter for Avro
URL: https://github.com/apache/incubator-gobblin/pull/2806#discussion_r346550041
 
 

 ##########
 File path: 
gobblin-core/src/main/java/org/apache/gobblin/converter/avro/AvroRecursionEliminatingConverter.java
 ##########
 @@ -0,0 +1,65 @@
+/*
+ * 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.gobblin.converter.avro;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.commons.math3.util.Pair;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.configuration.WorkUnitState;
+import org.apache.gobblin.converter.AvroToAvroConverterBase;
+import org.apache.gobblin.converter.DataConversionException;
+import org.apache.gobblin.converter.SchemaConversionException;
+import org.apache.gobblin.converter.SingleRecordIterable;
+import org.apache.gobblin.util.AvroUtils;
+
+
+@Slf4j
+public class AvroRecursionEliminatingConverter extends AvroToAvroConverterBase 
{
+  @Override
+  public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit)
+      throws SchemaConversionException {
+    Pair<Schema, List<AvroUtils.SchemaEntry>> results = 
AvroUtils.dropRecursiveFields(inputSchema);
+    List<AvroUtils.SchemaEntry> recursiveFields = results.getSecond();
+    if (!recursiveFields.isEmpty()) {
+      log.info("Schema " + inputSchema.getFullName() + " is recursive. Will 
drop fields [" +
+          recursiveFields.stream().map(entry -> 
entry.getFieldName()).collect(Collectors.joining(",")) + "]");
+      log.info("Schema %s is recursive. Will drop fields [%s]", 
inputSchema.getFullName(),
 
 Review comment:
   fixed
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 343752)
    Time Spent: 50m  (was: 40m)

> Support automatic recursion removal from schemas
> ------------------------------------------------
>
>                 Key: GOBBLIN-957
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-957
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Shirshanka Das
>            Assignee: Shirshanka Das
>            Priority: Major
>              Labels: avro
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Analytics engines like Hive etc cannot handle recursive schemas: schemas 
> where inner fields can refer to the wrapping type. 
> This Jira proposes that we provide support for automatic recursion removal in 
> data during data ingestion. 
> The simple proposal is to just drop the fields in the schema that introduce 
> the recursion. 
> e.g.  (pseudo-schema)
> User { 
>  string name;
>  User friend;
> }
> gets converted to :
> User { 
>    string name;
> }
>  
> A more sophisticated solution would be to do one or two levels of 
> "schema-unrolling" before dropping data. 
> e.g. 
> output schema with one-level unrolling would look like: 
> User { 
>    string name;
>    User1 friend;
> }
> User 1 { 
>     string name;
>   }
>  
>  
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to