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

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

                Author: ASF GitHub Bot
            Created on: 17/May/19 16:30
            Start Date: 17/May/19 16:30
    Worklog Time Spent: 10m 
      Work Description: autumnust commented on pull request #2637: 
[GOBBLIN-772]Implement Schema Comparison Strategy during Disctp
URL: https://github.com/apache/incubator-gobblin/pull/2637#discussion_r285199219
 
 

 ##########
 File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/extractor/FileAwareInputStreamExtractorWithCheckSchema.java
 ##########
 @@ -39,32 +42,109 @@
  * check if the schema matches the expected schema. If not it will abort the 
job.
  */
 
-public class FileAwareInputStreamExtractorWithCheckSchema extends 
FileAwareInputStreamExtractor{
+public class FileAwareInputStreamExtractorWithCheckSchema extends 
FileAwareInputStreamExtractor {
 
-  public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, 
CopyableFile file, WorkUnitState state)
-  {
+  public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, 
CopyableFile file, WorkUnitState state) {
     super(fs, file, state);
   }
-  public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, 
CopyableFile file)
-  {
+
+  public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, 
CopyableFile file) {
     this(fs, file, null);
   }
 
   @Override
-  protected FileAwareInputStream buildStream(FileSystem fsFromFile)
-      throws DataRecordException, IOException{
-    if(!schemaChecking(fsFromFile))
-    {
+  protected FileAwareInputStream buildStream(FileSystem fsFromFile) throws 
DataRecordException, IOException {
+    if (!schemaChecking(fsFromFile)) {
       throw new DataRecordException("Schema does not match the expected 
schema");
     }
     return super.buildStream(fsFromFile);
   }
 
-  protected boolean schemaChecking(FileSystem fsFromFile)
-      throws IOException {
+  protected boolean schemaChecking(FileSystem fsFromFile) throws IOException {
     DatumReader<GenericRecord> datumReader = new GenericDatumReader<>();
-    DataFileReader<GenericRecord> dataFileReader = new DataFileReader(new 
FsInput(this.file.getFileStatus().getPath(),fsFromFile), datumReader);
+    DataFileReader<GenericRecord> dataFileReader =
+        new DataFileReader(new FsInput(this.file.getFileStatus().getPath(), 
fsFromFile), datumReader);
     Schema schema = dataFileReader.getSchema();
-    return 
schema.toString().equals(this.state.getProp(ConfigurationKeys.COPY_EXPECTED_SCHEMA));
+    Schema expectedSchema = new 
Schema.Parser().parse(this.state.getProp(ConfigurationKeys.COPY_EXPECTED_SCHEMA));
+
+    return compare(schema, expectedSchema);
+  }
+
+  private boolean compare(Schema toValidate, Schema expected) {
 
 Review comment:
   Depending on the scope of your schema checking, this method can be reused 
for other purposes. May be make it static method or put in some utilities 
classes? 
 
----------------------------------------------------------------
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: 244124)
    Time Spent: 0.5h  (was: 20m)

> Implement Schema Comparison Strategy during Disctp
> --------------------------------------------------
>
>                 Key: GOBBLIN-772
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-772
>             Project: Apache Gobblin
>          Issue Type: Task
>            Reporter: Zihan Li
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> We need a schema comparison strategy to make sure the real schema and the 
> expected schema have matching field names and types.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to