-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRILL-8474: Adding Daffodil to Drill as a contrib. #2909
Open
mbeckerle
wants to merge
3
commits into
apache:master
Choose a base branch
from
mbeckerle:daffodil-2835-squashed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Daffodil 'Format' Reader | ||
This plugin enables Drill to read DFDL-described data from files by way of the Apache Daffodil DFDL implementation. | ||
|
||
## Validation | ||
|
||
Data read by Daffodil is always validated using Daffodil's Limited Validation mode. | ||
|
||
TBD: do we need an option to control escalating validation errors to fatal? Currently this is not provided. | ||
|
||
## Limitations: TBD | ||
|
||
At the moment, the DFDL schema is found on the local file system, which won't support Drill's distributed architecture. | ||
|
||
There are restrictions on the DFDL schemas that this can handle. | ||
|
||
In particular, all element children must have distinct element names, including across choice branches. | ||
(This rules out a number of large DFDL schemas.) | ||
|
||
TBD: Auto renaming as part of the Daffodil-to-Drill metadata mapping? | ||
|
||
The data is parsed fully from its native form into a Drill data structure held in memory. | ||
No attempt is made to avoid access to parts of the DFDL-described data that are not needed to answer the query. | ||
|
||
If the data is not well-formed, an error occurs and the query fails. | ||
|
||
If the data is invalid, and validity checking by Daffodil is enabled, then an error occurs and the query fails. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
|
||
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. | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>drill-contrib-parent</artifactId> | ||
<groupId>org.apache.drill.contrib</groupId> | ||
<version>1.22.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>drill-format-daffodil</artifactId> | ||
<name>Drill : Contrib : Format : Daffodil</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.drill.exec</groupId> | ||
<artifactId>drill-java-exec</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.daffodil</groupId> | ||
<artifactId>daffodil-japi_2.12</artifactId> | ||
<version>3.8.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.daffodil</groupId> | ||
<artifactId>daffodil-runtime1_2.12</artifactId> | ||
<version>3.8.0</version> | ||
</dependency> | ||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>org.apache.drill.exec</groupId> | ||
<artifactId>drill-java-exec</artifactId> | ||
<classifier>tests</classifier> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.drill</groupId> | ||
<artifactId>drill-common</artifactId> | ||
<classifier>tests</classifier> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-java-sources</id> | ||
<phase>process-sources</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${basedir}/target/classes/org/apache/drill/exec/store/daffodil | ||
</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>src/main/java/org/apache/drill/exec/store/daffodil</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
181 changes: 181 additions & 0 deletions
181
...rmat-daffodil/src/main/java/org/apache/drill/exec/store/daffodil/DaffodilBatchReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* 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.drill.exec.store.daffodil; | ||
|
||
import org.apache.daffodil.japi.DataProcessor; | ||
import org.apache.drill.common.AutoCloseables; | ||
import org.apache.drill.common.exceptions.CustomErrorContext; | ||
import org.apache.drill.common.exceptions.UserException; | ||
import org.apache.drill.exec.physical.impl.scan.v3.ManagedReader; | ||
import org.apache.drill.exec.physical.impl.scan.v3.file.FileDescrip; | ||
import org.apache.drill.exec.physical.impl.scan.v3.file.FileSchemaNegotiator; | ||
import org.apache.drill.exec.physical.resultSet.RowSetLoader; | ||
import org.apache.drill.exec.record.metadata.TupleMetadata; | ||
import org.apache.drill.exec.store.daffodil.schema.DaffodilDataProcessorFactory; | ||
import org.apache.drill.exec.store.dfs.DrillFileSystem; | ||
import org.apache.drill.exec.store.dfs.easy.EasySubScan; | ||
import org.apache.hadoop.fs.Path; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Objects; | ||
|
||
import static org.apache.drill.exec.store.daffodil.schema.DaffodilDataProcessorFactory.CompileFailure; | ||
import static org.apache.drill.exec.store.daffodil.schema.DrillDaffodilSchemaUtils.daffodilDataProcessorToDrillSchema; | ||
|
||
public class DaffodilBatchReader implements ManagedReader { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DaffodilBatchReader.class); | ||
private final RowSetLoader rowSetLoader; | ||
private final CustomErrorContext errorContext; | ||
private final DaffodilMessageParser dafParser; | ||
private final InputStream dataInputStream; | ||
|
||
public DaffodilBatchReader(DaffodilReaderConfig readerConfig, EasySubScan scan, | ||
FileSchemaNegotiator negotiator) { | ||
|
||
errorContext = negotiator.parentErrorContext(); | ||
DaffodilFormatConfig dafConfig = readerConfig.plugin.getConfig(); | ||
|
||
String schemaURIString = dafConfig.getSchemaURI(); // "schema/complexArray1.dfdl.xsd"; | ||
String rootName = dafConfig.getRootName(); | ||
String rootNamespace = dafConfig.getRootNamespace(); | ||
boolean validationMode = dafConfig.getValidationMode(); | ||
|
||
URI dfdlSchemaURI; | ||
try { | ||
dfdlSchemaURI = new URI(schemaURIString); | ||
} catch (URISyntaxException e) { | ||
throw UserException.validationError(e).build(logger); | ||
} | ||
|
||
FileDescrip file = negotiator.file(); | ||
DrillFileSystem fs = file.fileSystem(); | ||
URI fsSchemaURI = fs.getUri().resolve(dfdlSchemaURI); | ||
|
||
DaffodilDataProcessorFactory dpf = new DaffodilDataProcessorFactory(); | ||
DataProcessor dp; | ||
try { | ||
dp = dpf.getDataProcessor(fsSchemaURI, validationMode, rootName, rootNamespace); | ||
} catch (CompileFailure e) { | ||
throw UserException.dataReadError(e) | ||
.message(String.format("Failed to get Daffodil DFDL processor for: %s", fsSchemaURI)) | ||
.addContext(errorContext).addContext(e.getMessage()).build(logger); | ||
} | ||
// Create the corresponding Drill schema. | ||
// Note: this could be a very large schema. Think of a large complex RDBMS schema, | ||
// all of it, hundreds of tables, but all part of the same metadata tree. | ||
TupleMetadata drillSchema = daffodilDataProcessorToDrillSchema(dp); | ||
// Inform Drill about the schema | ||
negotiator.tableSchema(drillSchema, true); | ||
|
||
// | ||
// DATA TIME: Next we construct the runtime objects, and open files. | ||
// | ||
// We get the DaffodilMessageParser, which is a stateful driver for daffodil that | ||
// actually does the parsing. | ||
rowSetLoader = negotiator.build().writer(); | ||
|
||
// We construct the Daffodil InfosetOutputter which the daffodil parser uses to | ||
// convert infoset event calls to fill in a Drill row via a rowSetLoader. | ||
DaffodilDrillInfosetOutputter outputter = new DaffodilDrillInfosetOutputter(rowSetLoader); | ||
|
||
// Now we can set up the dafParser with the outputter it will drive with | ||
// the parser-produced infoset. | ||
dafParser = new DaffodilMessageParser(dp); // needs further initialization after this. | ||
dafParser.setInfosetOutputter(outputter); | ||
|
||
Path dataPath = file.split().getPath(); | ||
// Lastly, we open the data stream | ||
try { | ||
dataInputStream = fs.openPossiblyCompressedStream(dataPath); | ||
} catch (IOException e) { | ||
throw UserException.dataReadError(e) | ||
.message(String.format("Failed to open input file: %s", dataPath.toString())) | ||
.addContext(errorContext).addContext(e.getMessage()).build(logger); | ||
} | ||
// And lastly,... tell daffodil the input data stream. | ||
dafParser.setInputStream(dataInputStream); | ||
} | ||
|
||
/** | ||
* This is the core of actual processing - data movement from Daffodil to Drill. | ||
* <p> | ||
* If there is space in the batch, and there is data available to parse then this calls the | ||
* daffodil parser, which parses data, delivering it to the rowWriter by way of the infoset | ||
* outputter. | ||
* <p> | ||
* Repeats until the rowWriter is full (a batch is full), or there is no more data, or a parse | ||
* error ends execution with a throw. | ||
* <p> | ||
* Validation errors and other warnings are not errors and are logged but do not cause parsing to | ||
* fail/throw. | ||
* | ||
* @return true if there are rows retrieved, false if no rows were retrieved, which means no more | ||
* will ever be retrieved (end of data). | ||
* @throws RuntimeException | ||
* on parse errors. | ||
*/ | ||
@Override | ||
public boolean next() { | ||
// Check assumed invariants | ||
// We don't know if there is data or not. This could be called on an empty data file. | ||
// We DO know that this won't be called if there is no space in the batch for even 1 | ||
// row. | ||
if (dafParser.isEOF()) { | ||
return false; // return without even checking for more rows or trying to parse. | ||
} | ||
while (rowSetLoader.start() && !dafParser.isEOF()) { // we never zero-trip this loop. | ||
// the predicate is always true once. | ||
dafParser.parse(); | ||
if (dafParser.isProcessingError()) { | ||
assert (Objects.nonNull(dafParser.getDiagnostics())); | ||
throw UserException.dataReadError().message(dafParser.getDiagnosticsAsString()) | ||
.addContext(errorContext).build(logger); | ||
} | ||
if (dafParser.isValidationError()) { | ||
logger.warn(dafParser.getDiagnosticsAsString()); | ||
// Note that even if daffodil is set to not validate, validation errors may still occur | ||
// from DFDL's "recoverableError" assertions. | ||
} | ||
rowSetLoader.save(); | ||
} | ||
int nRows = rowSetLoader.rowCount(); | ||
assert nRows > 0; // This cannot be zero. If the parse failed we will have already thrown out | ||
// of here. | ||
return true; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
AutoCloseables.closeSilently(dataInputStream); | ||
} | ||
} | ||
|
||
class DaffodilReaderConfig { | ||
final DaffodilFormatPlugin plugin; | ||
|
||
DaffodilReaderConfig(DaffodilFormatPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this section do? I noticed that the msaccess contrib doesn't have this section in its pom.xml.