Skip to content

Commit

Permalink
Merge pull request #8740 from youngsofun/ref
Browse files Browse the repository at this point in the history
refactor(out format): move output_format_xxx.rs to a sub-folder.
  • Loading branch information
BohuTANG authored Nov 11, 2022
2 parents 9f8c052 + 84f7df9 commit 1b9174a
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 69 deletions.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions src/query/formats/src/field_encoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod field_encoder_csv;
mod field_encoder_json;
mod field_encoder_row_based;
mod field_encoder_tsv;
mod field_encoder_values;
mod csv;
mod helpers;
mod json;
mod row_based;
mod tsv;
mod values;

pub use field_encoder_csv::FieldEncoderCSV;
pub use field_encoder_json::FieldEncoderJSON;
pub use field_encoder_row_based::FieldEncoderRowBased;
pub use field_encoder_tsv::FieldEncoderTSV;
pub use field_encoder_values::FieldEncoderValues;
pub use csv::FieldEncoderCSV;
pub use helpers::CommonSettings;
pub use json::FieldEncoderJSON;
pub use row_based::FieldEncoderRowBased;
pub use tsv::FieldEncoderTSV;
pub use values::FieldEncoderValues;
File renamed without changes.
89 changes: 38 additions & 51 deletions src/query/formats/src/file_format_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ use common_meta_types::StageFileFormatType;
use common_settings::Settings;

use super::clickhouse::ClickhouseSuffix;
use crate::output_format::CSVOutputFormat;
use crate::output_format::CSVWithNamesAndTypesOutputFormat;
use crate::output_format::CSVWithNamesOutputFormat;
use crate::output_format::NDJSONOutputFormatBase;
use crate::output_format::OutputFormat;
use crate::output_format_csv::CSVOutputFormat;
use crate::output_format_csv::CSVWithNamesAndTypesOutputFormat;
use crate::output_format_csv::CSVWithNamesOutputFormat;
use crate::output_format_json_each_row::JsonEachRowOutputFormatBase;
use crate::output_format_parquet::ParquetOutputFormat;
use crate::output_format_tsv::TSVOutputFormat;
use crate::output_format_tsv::TSVWithNamesAndTypesOutputFormat;
use crate::output_format_tsv::TSVWithNamesOutputFormat;
use crate::output_format::ParquetOutputFormat;
use crate::output_format::TSVOutputFormat;
use crate::output_format::TSVWithNamesAndTypesOutputFormat;
use crate::output_format::TSVWithNamesOutputFormat;
use crate::ClickhouseFormatType;

pub trait FileFormatTypeExt {
Expand Down Expand Up @@ -130,55 +130,42 @@ impl FileFormatOptionsExt {
match (options.headers, options.json_strings, options.json_compact) {
// string, compact, name, type
// not compact
(0, false, false) => Box::new(JsonEachRowOutputFormatBase::<
(0, false, false) => Box::new(NDJSONOutputFormatBase::<
false,
false,
false,
false,
>::create(schema, &options)),
(0, true, false) => Box::new(JsonEachRowOutputFormatBase::<
true,
false,
false,
false,
>::create(schema, &options)),
(0, true, false) => {
Box::new(NDJSONOutputFormatBase::<true, false, false, false>::create(
schema, &options,
))
}
// compact
(0, false, true) => Box::new(JsonEachRowOutputFormatBase::<
false,
true,
false,
false,
>::create(schema, &options)),
(0, true, true) => Box::new(JsonEachRowOutputFormatBase::<
true,
true,
false,
false,
>::create(schema, &options)),
(1, false, true) => Box::new(JsonEachRowOutputFormatBase::<
false,
true,
true,
false,
>::create(schema, &options)),
(1, true, true) => Box::new(JsonEachRowOutputFormatBase::<
true,
true,
true,
false,
>::create(schema, &options)),
(2, false, true) => Box::new(JsonEachRowOutputFormatBase::<
false,
true,
true,
true,
>::create(schema, &options)),
(2, true, true) => Box::new(JsonEachRowOutputFormatBase::<
true,
true,
true,
true,
>::create(schema, &options)),
(0, false, true) => {
Box::new(NDJSONOutputFormatBase::<false, true, false, false>::create(
schema, &options,
))
}
(0, true, true) => {
Box::new(NDJSONOutputFormatBase::<true, true, false, false>::create(
schema, &options,
))
}
(1, false, true) => {
Box::new(NDJSONOutputFormatBase::<false, true, true, false>::create(
schema, &options,
))
}
(1, true, true) => Box::new(
NDJSONOutputFormatBase::<true, true, true, false>::create(schema, &options),
),
(2, false, true) => Box::new(
NDJSONOutputFormatBase::<false, true, true, true>::create(schema, &options),
),
(2, true, true) => Box::new(
NDJSONOutputFormatBase::<true, true, true, true>::create(schema, &options),
),
_ => unreachable!(),
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/query/formats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ mod clickhouse;
pub mod field_encoder;
mod file_format_type;
pub mod output_format;
pub mod output_format_csv;
mod output_format_json_each_row;
mod output_format_parquet;
mod output_format_tsv;
mod output_format_values;

pub use clickhouse::ClickhouseFormatType;
pub use file_format_type::FileFormatOptionsExt;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@

use common_datablocks::DataBlock;
use common_exception::Result;
pub mod csv;
pub mod ndjson;
pub mod parquet;
pub mod tsv;
pub mod values;

pub use csv::CSVOutputFormat;
pub use csv::CSVWithNamesAndTypesOutputFormat;
pub use csv::CSVWithNamesOutputFormat;
pub use ndjson::NDJSONOutputFormatBase;
pub use parquet::ParquetOutputFormat;
pub use tsv::TSVOutputFormat;
pub use tsv::TSVWithNamesAndTypesOutputFormat;
pub use tsv::TSVWithNamesOutputFormat;
pub use values::ValuesOutputFormat;

pub trait OutputFormat: Send {
fn serialize_block(&mut self, data_block: &DataBlock) -> Result<Vec<u8>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::field_encoder::FieldEncoderRowBased;
use crate::output_format::OutputFormat;
use crate::FileFormatOptionsExt;

pub struct JsonEachRowOutputFormatBase<
pub struct NDJSONOutputFormatBase<
const STRINGS: bool,
const COMPACT: bool,
const WITH_NAMES: bool,
Expand All @@ -33,7 +33,7 @@ pub struct JsonEachRowOutputFormatBase<
}

impl<const STRINGS: bool, const COMPACT: bool, const WITH_NAMES: bool, const WITH_TYPES: bool>
JsonEachRowOutputFormatBase<STRINGS, COMPACT, WITH_NAMES, WITH_TYPES>
NDJSONOutputFormatBase<STRINGS, COMPACT, WITH_NAMES, WITH_TYPES>
{
pub fn create(schema: DataSchemaRef, options: &FileFormatOptionsExt) -> Self {
let field_encoder = FieldEncoderJSON::create(options);
Expand All @@ -59,7 +59,7 @@ impl<const STRINGS: bool, const COMPACT: bool, const WITH_NAMES: bool, const WIT
}

impl<const STRINGS: bool, const COMPACT: bool, const WITH_NAMES: bool, const WITH_TYPES: bool>
OutputFormat for JsonEachRowOutputFormatBase<STRINGS, COMPACT, WITH_NAMES, WITH_TYPES>
OutputFormat for NDJSONOutputFormatBase<STRINGS, COMPACT, WITH_NAMES, WITH_TYPES>
{
fn serialize_block(&mut self, block: &DataBlock) -> Result<Vec<u8>> {
let rows_size = block.column(0).len();
Expand Down
File renamed without changes.

1 comment on commit 1b9174a

@vercel
Copy link

@vercel vercel bot commented on 1b9174a Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend-git-main-databend.vercel.app
databend.vercel.app
databend.rs

Please sign in to comment.