You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2019/04/08 22:39:36 UTC
[GitHub] [incubator-gobblin] autumnust commented on a change in pull request
#2593: enable schema check for ticket ETL-8753
autumnust commented on a change in pull request #2593: enable schema check for ticket ETL-8753
URL: https://github.com/apache/incubator-gobblin/pull/2593#discussion_r273264990
##########
File path: gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/extractor/FileAwareInputStreamExtractorWithCheckSchema.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.data.management.copy.extractor;
+
+import java.io.IOException;
+
+import org.apache.avro.Schema;
+import org.apache.avro.file.DataFileReader;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.mapred.FsInput;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+
+import org.apache.gobblin.configuration.WorkUnitState;
+import org.apache.gobblin.data.management.copy.CopyableFile;
+import org.apache.gobblin.data.management.copy.FileAwareInputStream;
+import org.apache.gobblin.source.extractor.DataRecordException;
+import org.apache.gobblin.util.HadoopUtils;
+
+
+
+public class FileAwareInputStreamExtractorWithCheckSchema extends FileAwareInputStreamExtractor{
+ public final static String EXPECTED_SCHEMA = "expected.schema";
+
+ public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, CopyableFile file, WorkUnitState state)
+ {
+ super(fs, file, state);
+ }
+ public FileAwareInputStreamExtractorWithCheckSchema(FileSystem fs, CopyableFile file)
+ {
+ this(fs, file, null);
+ }
+
+ @Override
+ public FileAwareInputStream readRecord(@Deprecated FileAwareInputStream reuse)
+ throws DataRecordException, IOException {
+ if (!this.recordRead) {
+ Configuration conf =
+ this.state == null ? HadoopUtils.newConfiguration() : HadoopUtils.getConfFromState(this.state);
+ FileSystem fsFromFile = this.file.getOrigin().getPath().getFileSystem(conf);
+ DatumReader<GenericRecord> datumReader = new GenericDatumReader<>();
Review comment:
This schema validation will only work for Avro, which is good for now. For extensibility, we could encapsulate it into a method like `schemaChecking` or a better name you could think of, so that in the future we can just extend this class and override this method for different format.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services