Skip to content

Apache DataFusion SQL Query Engine

ARROW-363: [Java/C++] integration testing harness, initial integration tests

Wes McKinney74b2ad28c23b
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..a00cbba065
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,26 @@
+# 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.
+
+# Compiled source
+*.a
+*.dll
+*.o
+*.py[ocd]
+*.so
+*.dylib
+.build_cache_dir
+MANIFEST
diff --git a/dev/release/run-rat.sh b/dev/release/run-rat.sh
index d8ec6507fc..e26dd58969 100755
--- a/dev/release/run-rat.sh
+++ b/dev/release/run-rat.sh
@@ -28,6 +28,7 @@ $RAT $1 \
-e ".*" \
-e mman.h \
-e "*_generated.h" \
+ -e "*.json" \
-e random.h \
-e status.cc \
-e status.h \
@@ -49,5 +50,3 @@ else
echo "${UNAPPROVED} unapproved licences. Check rat report: rat.txt"
exit 1
fi
-
-
diff --git a/format/IPC.md b/format/IPC.md
index 3f78126ef5..a55dcdff48 100644
--- a/format/IPC.md
+++ b/format/IPC.md
@@ -15,3 +15,109 @@
# Interprocess messaging / communication (IPC)
## File format
+
+We define a self-contained "file format" containing an Arrow schema along with
+one or more record batches defining a dataset. See [format/File.fbs][1] for the
+precise details of the file metadata.
+
+In general, the file looks like:
+
+```
+<magic number "ARROW1">
+<empty padding bytes [to 64 byte boundary]>
+<DICTIONARY 0>
+...
+<DICTIONARY k - 1>
+<RECORD BATCH 0>
+...
+<RECORD BATCH n - 1>
+<METADATA org.apache.arrow.flatbuf.Footer>
+<metadata_size: int32>
+<magic number "ARROW1">
+```
+
+See the File.fbs document for details about the Flatbuffers metadata. The
+record batches have a particular structure, defined next.
+
+### Record batches
+
+The record batch metadata is written as a flatbuffer (see
+[format/Message.fbs][2] -- the RecordBatch message type) prefixed by its size,
+followed by each of the memory buffers in the batch written end to end (with
+appropriate alignment and padding):
+
+```
+<int32: metadata flatbuffer size>
+<metadata: org.apache.arrow.flatbuf.RecordBatch>
+<padding bytes [to 64-byte boundary]>
+<body: buffers end to end>
+```
+
+The `RecordBatch` metadata contains a depth-first (pre-order) flattened set of
+field metadata and physical memory buffers (some comments from [Message.fbs][2]
+have been shortened / removed):
+
+```
+table RecordBatch {
+ length: int;
+ nodes: [FieldNode];
+ buffers: [Buffer];
+}
+
+struct FieldNode {
+ /// The number of value slots in the Arrow array at this level of a nested
+ /// tree
+ length: int;
+
+ /// The number of observed nulls. Fields with null_count == 0 may choose not
+ /// to write their physical validity bitmap out as a materialized buffer,
+ /// instead setting the length of the bitmap buffer to 0.
+ null_count: int;
+}
+
+struct Buffer {
+ /// The shared memory page id where this buffer is located. Currently this is
+ /// not used
+ page: int;
+
+ /// The relative offset into the shared memory page where the bytes for this
+ /// buffer starts
+ offset: long;
+
+ /// The absolute length (in bytes) of the memory buffer. The memory is found
+ /// from offset (inclusive) to offset + length (non-inclusive).
+ length: long;
+}
+```
+
+In the context of a file, the `page` is not used, and the `Buffer` offsets use
+as a frame of reference the start of the segment where they are written in the
+file. So, while in a general IPC setting these offsets may be anyplace in one
+or more shared memory regions, in the file format the offsets start from 0.
+
+The location of a record batch and the size of the metadata block as well as
+the body of buffers is stored in the file footer:
+
+```
+struct Block {
+ offset: long;
+ metaDataLength: int;
+ bodyLength: long;
+}
+```
+
+Some notes about this
+
+* The `Block` offset indicates the starting byte of the record batch.
+* The metadata length includes the flatbuffer size, the record batch metadata
+ flatbuffer, and any padding bytes
+
+
+### Dictionary batches
+
+Dictionary batches have not yet been implemented, while they are provided for
+in the metadata. For the time being, the `DICTIONARY` segments shown above in
+the file do not appear in any of the file implementations.
+
+[1]: https://github.com/apache/arrow/blob/master/format/File.fbs
+[1]: https://github.com/apache/arrow/blob/master/format/Message.fbs
\ No newline at end of file
diff --git a/format/Message.fbs b/format/Message.fbs
index 2ec9fd1817..d07d0666dc 100644
--- a/format/Message.fbs
+++ b/format/Message.fbs
@@ -18,7 +18,8 @@
namespace org.apache.arrow.flatbuf;
enum MetadataVersion:short {
- V1_SNAPSHOT
+ V1,
+ V2
}
/// ----------------------------------------------------------------------
diff --git a/integration/data/simple.json b/integration/data/simple.json
new file mode 100644
index 0000000000..a91b405d4f
--- /dev/null
+++ b/integration/data/simple.json
@@ -0,0 +1,66 @@
+{
+ "schema": {
+ "fields": [
+ {
+ "name": "foo",
+ "type": {"name": "int", "isSigned": true, "bitWidth": 32},
+ "nullable": true, "children": [],
+ "typeLayout": {
+ "vectors": [
+ {"type": "VALIDITY", "typeBitWidth": 1},
+ {"type": "DATA", "typeBitWidth": 32}
+ ]
+ }
+ },
+ {
+ "name": "bar",
+ "type": {"name": "floatingpoint", "precision": "DOUBLE"},
+ "nullable": true, "children": [],
+ "typeLayout": {
+ "vectors": [
+ {"type": "VALIDITY", "typeBitWidth": 1},
+ {"type": "DATA", "typeBitWidth": 64}
+ ]
+ }
+ },
+ {
+ "name": "baz",
+ "type": {"name": "utf8"},
+ "nullable": true, "children": [],
+ "typeLayout": {
+ "vectors": [
+ {"type": "VALIDITY", "typeBitWidth": 1},
+ {"type": "OFFSET", "typeBitWidth": 32},
+ {"type": "DATA", "typeBitWidth": 64}
+ ]
+ }
+ }
+ ]
+ },
+ "batches": [
+ {
+ "count": 5,
+ "columns": [
+ {
+ "name": "foo",
+ "count": 5,
+ "VALIDITY": [1, 0, 1, 1, 1],
+ "DATA": [1, 2, 3, 4, 5]
+ },
+ {
+ "name": "bar",
+ "count": 5,
+ "VALIDITY": [1, 0, 0, 1, 1],
+ "DATA": [1.0, 2.0, 3.0, 4.0, 5.0]
+ },
+ {
+ "name": "baz",
+ "count": 5,
+ "VALIDITY": [1, 0, 0, 1, 1],
+ "OFFSET": [0, 2, 2, 2, 5, 9],
+ "DATA": ["aa", "", "", "bbb", "cccc"]
+ }
+ ]
+ }
+ ]
+}
diff --git a/integration/integration_test.py b/integration/integration_test.py
new file mode 100644
index 0000000000..6ea634d779
--- /dev/null
+++ b/integration/integration_test.py
@@ -0,0 +1,177 @@
+# 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.
+
+import argparse
+import glob
+import itertools
+import os
+import six
+import subprocess
+import tempfile
+import uuid
+
+
+ARROW_HOME = os.path.abspath(__file__).rsplit("/", 2)[0]
+
+
+def guid():
+ return uuid.uuid4().hex
+
+
+def run_cmd(cmd):
+ if isinstance(cmd, six.string_types):
+ cmd = cmd.split(' ')
+
+ try:
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as e:
+ # this avoids hiding the stdout / stderr of failed processes
+ print('Command failed: %s' % ' '.join(cmd))
+ print('With output:')
+ print('--------------')
+ print(e.output)
+ print('--------------')
+ raise e
+
+ if isinstance(output, six.binary_type):
+ output = output.decode('utf-8')
+ return output
+
+
+class IntegrationRunner(object):
+
+ def __init__(self, json_files, testers, debug=False):
+ self.json_files = json_files
+ self.testers = testers
+ self.temp_dir = tempfile.mkdtemp()
+ self.debug = debug
+
+ def run(self):
+ for producer, consumer in itertools.product(self.testers,
+ self.testers):
+ if producer is consumer:
+ continue
+
+ print('-- {0} producing, {1} consuming'.format(producer.name,
+ consumer.name))
+
+ for json_path in self.json_files:
+ print('Testing with {0}'.format(json_path))
+
+ arrow_path = os.path.join(self.temp_dir, guid())
+
+ producer.json_to_arrow(json_path, arrow_path)
+ consumer.validate(json_path, arrow_path)
+
+
+class Tester(object):
+
+ def __init__(self, debug=False):
+ self.debug = debug
+
+ def json_to_arrow(self, json_path, arrow_path):
+ raise NotImplementedError
+
+ def validate(self, json_path, arrow_path):
+ raise NotImplementedError
+
+
+class JavaTester(Tester):
+
+ ARROW_TOOLS_JAR = os.path.join(ARROW_HOME,
+ 'java/tools/target/arrow-tools-0.1.1-'
+ 'SNAPSHOT-jar-with-dependencies.jar')
+
+ name = 'Java'
+
+ def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):
+ cmd = ['java', '-cp', self.ARROW_TOOLS_JAR,
+ 'org.apache.arrow.tools.Integration']
+
+ if arrow_path is not None:
+ cmd.extend(['-a', arrow_path])
+
+ if json_path is not None:
+ cmd.extend(['-j', json_path])
+
+ cmd.extend(['-c', command])
+
+ if self.debug:
+ print(' '.join(cmd))
+
+ return run_cmd(cmd)
+
+ def validate(self, json_path, arrow_path):
+ return self._run(arrow_path, json_path, 'VALIDATE')
+
+ def json_to_arrow(self, json_path, arrow_path):
+ return self._run(arrow_path, json_path, 'JSON_TO_ARROW')
+
+
+class CPPTester(Tester):
+
+ CPP_INTEGRATION_EXE = os.environ.get(
+ 'ARROW_CPP_TESTER',
+ os.path.join(ARROW_HOME,
+ 'cpp/test-build/debug/json-integration-test'))
+
+ name = 'C++'
+
+ def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):
+ cmd = [self.CPP_INTEGRATION_EXE, '--integration']
+
+ if arrow_path is not None:
+ cmd.append('--arrow=' + arrow_path)
+
+ if json_path is not None:
+ cmd.append('--json=' + json_path)
+
+ cmd.append('--mode=' + command)
+
+ if self.debug:
+ print(' '.join(cmd))
+
+ return run_cmd(cmd)
+
+ def validate(self, json_path, arrow_path):
+ return self._run(arrow_path, json_path, 'VALIDATE')
+
+ def json_to_arrow(self, json_path, arrow_path):
+ return self._run(arrow_path, json_path, 'JSON_TO_ARROW')
+
+
+def get_json_files():
+ glob_pattern = os.path.join(ARROW_HOME, 'integration', 'data', '*.json')
+ return glob.glob(glob_pattern)
+
+
+def run_all_tests(debug=False):
+ testers = [JavaTester(debug=debug), CPPTester(debug=debug)]
+ json_files = get_json_files()
+
+ runner = IntegrationRunner(json_files, testers, debug=debug)
+ runner.run()
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Arrow integration test CLI')
+ parser.add_argument('--debug', dest='debug', action='store_true',
+ default=False,
+ help='Run executables in debug mode as relevant')
+
+ args = parser.parse_args()
+ run_all_tests(debug=args.debug)