From 514b0d655cb7a20064592f3b709e76cb8bdbf967 Mon Sep 17 00:00:00 2001 From: mqy Date: Wed, 16 Dec 2020 19:33:12 +0800 Subject: [PATCH 1/7] regen with flatc @ commit f8b203c9: flatc --filename-suffix --rust -o rust/arrow/src/ipc/gen/ format/*.fbs --- rust/arrow/src/ipc/gen/File.rs | 475 ++- rust/arrow/src/ipc/gen/Message.rs | 1517 +++---- rust/arrow/src/ipc/gen/Schema.rs | 5174 ++++++++++++------------ rust/arrow/src/ipc/gen/SparseTensor.rs | 2569 ++++++------ rust/arrow/src/ipc/gen/Tensor.rs | 1358 ++++--- 5 files changed, 5667 insertions(+), 5426 deletions(-) diff --git a/rust/arrow/src/ipc/gen/File.rs b/rust/arrow/src/ipc/gen/File.rs index af798ceae86..5cbc106e0da 100644 --- a/rust/arrow/src/ipc/gen/File.rs +++ b/rust/arrow/src/ipc/gen/File.rs @@ -1,61 +1,86 @@ -// 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. +// automatically generated by the FlatBuffers compiler, do not modify -#![allow(dead_code)] -#![allow(unused_imports)] -use crate::ipc::gen::Schema::*; -use flatbuffers::EndianScalar; -use std::{cmp::Ordering, mem}; -// automatically generated by the FlatBuffers compiler, do not modify +#![allow(unused_imports, dead_code)] + +use crate::Schema_generated::*; +use std::mem; +use std::cmp::Ordering; + +extern crate flatbuffers; +use self::flatbuffers::EndianScalar; + +#[allow(unused_imports, dead_code)] +pub mod org { + + use crate::Schema_generated::*; + use std::mem; + use std::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] +pub mod apache { + + use crate::Schema_generated::*; + use std::mem; + use std::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] +pub mod arrow { + + use crate::Schema_generated::*; + use std::mem; + use std::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] +pub mod flatbuf { + + use crate::Schema_generated::*; + use std::mem; + use std::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::EndianScalar; // struct Block, aligned to 8 #[repr(C, align(8))] #[derive(Clone, Copy, PartialEq)] pub struct Block { - offset_: i64, - metaDataLength_: i32, - padding0__: u32, - bodyLength_: i64, + offset_: i64, + metaDataLength_: i32, + padding0__: u32, + bodyLength_: i64, } // pub struct Block impl std::fmt::Debug for Block { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct("Block") - .field("offset", &self.offset()) - .field("metaDataLength", &self.metaDataLength()) - .field("bodyLength", &self.bodyLength()) - .finish() - } + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("Block") + .field("offset", &self.offset()) + .field("metaDataLength", &self.metaDataLength()) + .field("bodyLength", &self.bodyLength()) + .finish() + } } +impl flatbuffers::SimpleToVerifyInSlice for Block {} impl flatbuffers::SafeSliceAccess for Block {} impl<'a> flatbuffers::Follow<'a> for Block { - type Inner = &'a Block; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - <&'a Block>::follow(buf, loc) - } + type Inner = &'a Block; + #[inline] + fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + <&'a Block>::follow(buf, loc) + } } impl<'a> flatbuffers::Follow<'a> for &'a Block { - type Inner = &'a Block; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - flatbuffers::follow_cast_ref::(buf, loc) - } + type Inner = &'a Block; + #[inline] + fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + flatbuffers::follow_cast_ref::(buf, loc) + } } impl<'b> flatbuffers::Push for Block { type Output = Block; @@ -79,29 +104,38 @@ impl<'b> flatbuffers::Push for &'b Block { } } +impl<'a> flatbuffers::Verifiable for Block { + #[inline] + fn run_verifier<'o, 'b>( + v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.in_buffer::(pos) + } +} impl Block { - pub fn new(_offset: i64, _metaDataLength: i32, _bodyLength: i64) -> Self { - Block { - offset_: _offset.to_little_endian(), - metaDataLength_: _metaDataLength.to_little_endian(), - bodyLength_: _bodyLength.to_little_endian(), + pub fn new(_offset: i64, _metaDataLength: i32, _bodyLength: i64) -> Self { + Block { + offset_: _offset.to_little_endian(), + metaDataLength_: _metaDataLength.to_little_endian(), + bodyLength_: _bodyLength.to_little_endian(), - padding0__: 0, - } - } - /// Index to the start of the RecordBlock (note this is past the Message header) - pub fn offset(&self) -> i64 { - self.offset_.from_little_endian() - } - /// Length of the metadata - pub fn metaDataLength(&self) -> i32 { - self.metaDataLength_.from_little_endian() - } - /// Length of the data (this is aligned so there can be a gap between this and - /// the metadata). - pub fn bodyLength(&self) -> i64 { - self.bodyLength_.from_little_endian() + padding0__: 0, } + } + /// Index to the start of the RecordBlock (note this is past the Message header) + pub fn offset(&self) -> i64 { + self.offset_.from_little_endian() + } + /// Length of the metadata + pub fn metaDataLength(&self) -> i32 { + self.metaDataLength_.from_little_endian() + } + /// Length of the data (this is aligned so there can be a gap between this and + /// the metadata). + pub fn bodyLength(&self) -> i64 { + self.bodyLength_.from_little_endian() + } } pub enum FooterOffset {} @@ -111,44 +145,35 @@ pub enum FooterOffset {} /// Arrow File metadata /// pub struct Footer<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for Footer<'a> { type Inner = Footer<'a>; #[inline] fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table { buf, loc }, - } + Self { _tab: flatbuffers::Table { buf, loc } } } } impl<'a> Footer<'a> { #[inline] pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Footer { _tab: table } + Footer { + _tab: table, + } } #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args FooterArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = FooterBuilder::new(_fbb); - if let Some(x) = args.custom_metadata { - builder.add_custom_metadata(x); - } - if let Some(x) = args.recordBatches { - builder.add_recordBatches(x); - } - if let Some(x) = args.dictionaries { - builder.add_dictionaries(x); - } - if let Some(x) = args.schema { - builder.add_schema(x); - } - builder.add_version(args.version); - builder.finish() + args: &'args FooterArgs<'args>) -> flatbuffers::WIPOffset> { + let mut builder = FooterBuilder::new(_fbb); + if let Some(x) = args.custom_metadata { builder.add_custom_metadata(x); } + if let Some(x) = args.recordBatches { builder.add_recordBatches(x); } + if let Some(x) = args.dictionaries { builder.add_dictionaries(x); } + if let Some(x) = args.schema { builder.add_schema(x); } + builder.add_version(args.version); + builder.finish() } pub const VT_VERSION: flatbuffers::VOffsetT = 4; @@ -157,56 +182,51 @@ impl<'a> Footer<'a> { pub const VT_RECORDBATCHES: flatbuffers::VOffsetT = 10; pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12; - #[inline] - pub fn version(&self) -> MetadataVersion { - self._tab - .get::(Footer::VT_VERSION, Some(MetadataVersion::V1)) - .unwrap() - } - #[inline] - pub fn schema(&self) -> Option> { - self._tab - .get::>>(Footer::VT_SCHEMA, None) - } - #[inline] - pub fn dictionaries(&self) -> Option<&'a [Block]> { - self._tab - .get::>>( - Footer::VT_DICTIONARIES, - None, - ) - .map(|v| v.safe_slice()) - } - #[inline] - pub fn recordBatches(&self) -> Option<&'a [Block]> { - self._tab - .get::>>( - Footer::VT_RECORDBATCHES, - None, - ) - .map(|v| v.safe_slice()) - } - /// User-defined metadata - #[inline] - pub fn custom_metadata( - &self, - ) -> Option>>> { - self._tab.get::>>, - >>(Footer::VT_CUSTOM_METADATA, None) - } + #[inline] + pub fn version(&self) -> MetadataVersion { + self._tab.get::(Footer::VT_VERSION, Some(MetadataVersion::V1)).unwrap() + } + #[inline] + pub fn schema(&self) -> Option> { + self._tab.get::>(Footer::VT_SCHEMA, None) + } + #[inline] + pub fn dictionaries(&self) -> Option<&'a [Block]> { + self._tab.get::>>(Footer::VT_DICTIONARIES, None).map(|v| v.safe_slice()) + } + #[inline] + pub fn recordBatches(&self) -> Option<&'a [Block]> { + self._tab.get::>>(Footer::VT_RECORDBATCHES, None).map(|v| v.safe_slice()) + } + /// User-defined metadata + #[inline] + pub fn custom_metadata(&self) -> Option>>> { + self._tab.get::>>>(Footer::VT_CUSTOM_METADATA, None) + } } +impl flatbuffers::Verifiable for Footer<'_> { + #[inline] + fn run_verifier<'o, 'b>( + v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::(&"version", Self::VT_VERSION, false)? + .visit_field::>(&"schema", Self::VT_SCHEMA, false)? + .visit_field::>>(&"dictionaries", Self::VT_DICTIONARIES, false)? + .visit_field::>>(&"recordBatches", Self::VT_RECORDBATCHES, false)? + .visit_field::>>>(&"custom_metadata", Self::VT_CUSTOM_METADATA, false)? + .finish(); + Ok(()) + } +} pub struct FooterArgs<'a> { pub version: MetadataVersion, pub schema: Option>>, pub dictionaries: Option>>, pub recordBatches: Option>>, - pub custom_metadata: Option< - flatbuffers::WIPOffset< - flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, - >, - >, + pub custom_metadata: Option>>>>, } impl<'a> Default for FooterArgs<'a> { #[inline] @@ -221,108 +241,141 @@ impl<'a> Default for FooterArgs<'a> { } } pub struct FooterBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> FooterBuilder<'a, 'b> { - #[inline] - pub fn add_version(&mut self, version: MetadataVersion) { - self.fbb_.push_slot::( - Footer::VT_VERSION, - version, - MetadataVersion::V1, - ); - } - #[inline] - pub fn add_schema(&mut self, schema: flatbuffers::WIPOffset>) { - self.fbb_ - .push_slot_always::>( - Footer::VT_SCHEMA, - schema, - ); - } - #[inline] - pub fn add_dictionaries( - &mut self, - dictionaries: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - Footer::VT_DICTIONARIES, - dictionaries, - ); - } - #[inline] - pub fn add_recordBatches( - &mut self, - recordBatches: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - Footer::VT_RECORDBATCHES, - recordBatches, - ); - } - #[inline] - pub fn add_custom_metadata( - &mut self, - custom_metadata: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_.push_slot_always::>( - Footer::VT_CUSTOM_METADATA, - custom_metadata, - ); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> FooterBuilder<'a, 'b> { - let start = _fbb.start_table(); - FooterBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) + #[inline] + pub fn add_version(&mut self, version: MetadataVersion) { + self.fbb_.push_slot::(Footer::VT_VERSION, version, MetadataVersion::V1); + } + #[inline] + pub fn add_schema(&mut self, schema: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Footer::VT_SCHEMA, schema); + } + #[inline] + pub fn add_dictionaries(&mut self, dictionaries: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Footer::VT_DICTIONARIES, dictionaries); + } + #[inline] + pub fn add_recordBatches(&mut self, recordBatches: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Footer::VT_RECORDBATCHES, recordBatches); + } + #[inline] + pub fn add_custom_metadata(&mut self, custom_metadata: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(Footer::VT_CUSTOM_METADATA, custom_metadata); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> FooterBuilder<'a, 'b> { + let start = _fbb.start_table(); + FooterBuilder { + fbb_: _fbb, + start_: start, } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl std::fmt::Debug for Footer<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut ds = f.debug_struct("Footer"); - ds.field("version", &self.version()); - ds.field("schema", &self.schema()); - ds.field("dictionaries", &self.dictionaries()); - ds.field("recordBatches", &self.recordBatches()); - ds.field("custom_metadata", &self.custom_metadata()); - ds.finish() - } + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut ds = f.debug_struct("Footer"); + ds.field("version", &self.version()); + ds.field("schema", &self.schema()); + ds.field("dictionaries", &self.dictionaries()); + ds.field("recordBatches", &self.recordBatches()); + ds.field("custom_metadata", &self.custom_metadata()); + ds.finish() + } } #[inline] +#[deprecated(since="1.13", note="Deprecated in favor of `root_as...` methods.")] pub fn get_root_as_footer<'a>(buf: &'a [u8]) -> Footer<'a> { - flatbuffers::get_root::>(buf) + unsafe { flatbuffers::root_unchecked::>(buf) } } #[inline] +#[deprecated(since="1.13", note="Deprecated in favor of `root_as...` methods.")] pub fn get_size_prefixed_root_as_footer<'a>(buf: &'a [u8]) -> Footer<'a> { - flatbuffers::get_size_prefixed_root::>(buf) + unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } } +#[inline] +/// Verifies that a buffer of bytes contains a `Footer` +/// and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_footer_unchecked`. +pub fn root_as_footer(buf: &[u8]) -> Result { + flatbuffers::root::