[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r204233444 --- Diff: flink-connectors/flink-connector-filesystem/src/main/java/org/apache/flink/streaming/connectors/fs/OrcFileWriter.java --- @@ -0,0 +1,252 @@ +/** + * 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.flink.streaming.connectors.fs; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + private TypeDescription schema; + + private String meatSchema; + + private transient org.apache.orc.Writer writer; + + private VectorizedRowBatch rowBatch; + + private CompressionKind compressionKind; + + private long writedRowSize; + + private OrcBatchWriter orcBatchWriter; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of a orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.meatSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { + typeInformations.add(schemaToTypeInfo(typeDescription)); + }); + + return new TableSchema( + fieldNames.toArray(new String[fieldNames.size()]), + typeInformations.toArray(new TypeInformation[typeInformations.size()])); + } + + @Override + public void write(T element) throws IOException { + Boolean isFill = orcBatchWriter.fill(rowBatch, element); + if (!isFill)
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r204232617 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r204231919 --- Diff: flink-connectors/flink-connector-filesystem/src/main/java/org/apache/flink/streaming/connectors/fs/OrcFileWriter.java --- @@ -0,0 +1,252 @@ +/** + * 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.flink.streaming.connectors.fs; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + private TypeDescription schema; + + private String meatSchema; + + private transient org.apache.orc.Writer writer; + + private VectorizedRowBatch rowBatch; + + private CompressionKind compressionKind; + + private long writedRowSize; + + private OrcBatchWriter orcBatchWriter; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of a orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.meatSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { + typeInformations.add(schemaToTypeInfo(typeDescription)); + }); + + return new TableSchema( + fieldNames.toArray(new String[fieldNames.size()]), + typeInformations.toArray(new TypeInformation[typeInformations.size()])); + } + + @Override + public void write(T element) throws IOException { + Boolean isFill = orcBatchWriter.fill(rowBatch, element); + if (!isFill)
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user sagarl commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200217627 --- Diff: flink-connectors/flink-connector-filesystem/src/main/java/org/apache/flink/streaming/connectors/fs/OrcFileWriter.java --- @@ -0,0 +1,252 @@ +/** + * 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.flink.streaming.connectors.fs; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + private TypeDescription schema; + + private String meatSchema; + + private transient org.apache.orc.Writer writer; + + private VectorizedRowBatch rowBatch; + + private CompressionKind compressionKind; + + private long writedRowSize; + + private OrcBatchWriter orcBatchWriter; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of a orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.meatSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { + typeInformations.add(schemaToTypeInfo(typeDescription)); + }); + + return new TableSchema( + fieldNames.toArray(new String[fieldNames.size()]), + typeInformations.toArray(new TypeInformation[typeInformations.size()])); + } + + @Override + public void write(T element) throws IOException { + Boolean isFill = orcBatchWriter.fill(rowBatch, element); + if (!isFill) {
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user sagarl commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200217021 --- Diff: flink-connectors/flink-connector-filesystem/src/main/java/org/apache/flink/streaming/connectors/fs/OrcFileWriter.java --- @@ -0,0 +1,252 @@ +/** + * 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.flink.streaming.connectors.fs; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + private TypeDescription schema; + + private String meatSchema; + + private transient org.apache.orc.Writer writer; + + private VectorizedRowBatch rowBatch; + + private CompressionKind compressionKind; + + private long writedRowSize; + + private OrcBatchWriter orcBatchWriter; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of a orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.meatSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { + typeInformations.add(schemaToTypeInfo(typeDescription)); + }); + + return new TableSchema( + fieldNames.toArray(new String[fieldNames.size()]), + typeInformations.toArray(new TypeInformation[typeInformations.size()])); + } + + @Override + public void write(T element) throws IOException { + Boolean isFill = orcBatchWriter.fill(rowBatch, element); + if (!isFill) {
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user yuruiz commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r201630927 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200892031 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200890648 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200889912 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200889601 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200888987 --- Diff: flink-connectors/flink-orc/pom.xml --- @@ -54,6 +54,14 @@ under the License. true + + org.apache.flink + flink-connector-filesystem_${scala.binary.version} + ${project.version} + + true + + org.apache.orc orc-core --- End diff -- Yes. We can upgrade it. Will update. ---
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200888235 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user wgtmac commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200879243 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user wgtmac commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200879624 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user wgtmac commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200878724 --- Diff: flink-connectors/flink-orc/pom.xml --- @@ -54,6 +54,14 @@ under the License. true + + org.apache.flink + flink-connector-filesystem_${scala.binary.version} + ${project.version} + + true + + org.apache.orc orc-core --- End diff -- Current orc version is 1.5.X. Should we upgrade it as well? ---
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user wgtmac commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200879775 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200833563 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200831458 --- Diff: flink-connectors/flink-orc/src/test/java/org/apache/flink/orc/OrcFileWriterTest.java --- @@ -0,0 +1,40 @@ +/** + * 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.flink.orc; + +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.types.Row; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link OrcFileWriter}. + */ +public class OrcFileWriterTest { + + @Test + public void testDuplicate() { + OrcFileWriter writer = new OrcFileWriter("struct"); --- End diff -- Yes. I will add more UTs for all in the next couple of days. ---
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user xndai commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200831360 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user zhangminglei commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200830833 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user xndai commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200830078 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user xndai commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200830111 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user xndai commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200830013 --- Diff: flink-connectors/flink-orc/src/main/java/org/apache/flink/orc/OrcFileWriter.java --- @@ -0,0 +1,269 @@ +/** + * 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.flink.orc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.streaming.connectors.fs.StreamWriterBase; +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.types.Row; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.orc.CompressionKind; +import org.apache.orc.OrcFile; +import org.apache.orc.TypeDescription; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.IntStream; + +import static org.apache.flink.orc.OrcBatchReader.schemaToTypeInfo; + +/** + * A {@link Writer} that writes the bucket files as Hadoop {@link OrcFile}. + * + * @param The type of the elements that are being written by the sink. + */ +public class OrcFileWriter extends StreamWriterBase { + + private static final long serialVersionUID = 3L; + + /** +* The description of the types in an ORC file. +*/ + private TypeDescription schema; + + /** +* The schema of an ORC file. +*/ + private String metaSchema; + + /** +* A row batch that will be written to the ORC file. +*/ + private VectorizedRowBatch rowBatch; + + /** +* The writer that fill the records into the batch. +*/ + private OrcBatchWriter orcBatchWriter; + + private transient org.apache.orc.Writer writer; + + private CompressionKind compressionKind; + + /** +* The number of rows that currently being written. +*/ + private long writedRowSize; + + /** +* Creates a new {@code OrcFileWriter} that writes orc files without compression. +* +* @param metaSchema The orc schema. +*/ + public OrcFileWriter(String metaSchema) { + this(metaSchema, CompressionKind.NONE); + } + + /** +* Create a new {@code OrcFileWriter} that writes orc file with the gaven +* schema and compression kind. +* +* @param metaSchema The schema of an orc file. +* @param compressionKind The compression kind to use. +*/ + public OrcFileWriter(String metaSchema, CompressionKind compressionKind) { + this.metaSchema = metaSchema; + this.schema = TypeDescription.fromString(metaSchema); + this.compressionKind = compressionKind; + } + + @Override + public void open(FileSystem fs, Path path) throws IOException { + writer = OrcFile.createWriter(path, OrcFile.writerOptions(fs.getConf()).setSchema(schema).compress(compressionKind)); + rowBatch = schema.createRowBatch(); + orcBatchWriter = new OrcBatchWriter(Arrays.asList(orcSchemaToTableSchema(schema).getTypes())); + } + + private TableSchema orcSchemaToTableSchema(TypeDescription orcSchema) { + List fieldNames = orcSchema.getFieldNames(); + List typeDescriptions = orcSchema.getChildren(); + List typeInformations = new ArrayList<>(); + + typeDescriptions.forEach(typeDescription -> { +
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
Github user xndai commented on a diff in the pull request: https://github.com/apache/flink/pull/6075#discussion_r200830153 --- Diff: flink-connectors/flink-orc/src/test/java/org/apache/flink/orc/OrcFileWriterTest.java --- @@ -0,0 +1,40 @@ +/** + * 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.flink.orc; + +import org.apache.flink.streaming.connectors.fs.Writer; +import org.apache.flink.types.Row; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link OrcFileWriter}. + */ +public class OrcFileWriterTest { + + @Test + public void testDuplicate() { + OrcFileWriter writer = new OrcFileWriter("struct"); --- End diff -- Need UTs for writing Orc files with all supported types. Also include negative cases, and cases where OrcBatchWriter.fill() returns false. ---
[GitHub] flink pull request #6075: [FLINK-9407] [hdfs connector] Support orc rolling ...
GitHub user zhangminglei opened a pull request: https://github.com/apache/flink/pull/6075 [FLINK-9407] [hdfs connector] Support orc rolling sink writer ## What is the purpose of the change In production environment, we often write file in orc format. So, this PR support a writer that for bucketingsink. And currently only basic data types are supported in this PR. ## Brief change log Add ```OrcFileWriter``` and the test file. ## Verifying this change Tests it with ```OrcFileWriterTest``` ## Does this pull request potentially affect one of the following parts: - Dependencies (does it add or upgrade a dependency): (yes - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no) - The serializers: (no) - The runtime per-record code paths (performance sensitive): (don't know) - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: ( no ) - The S3 file system connector: (no) ## Documentation - Does this pull request introduce a new feature? (yes) - If yes, how is the feature documented? (not documented now) You can merge this pull request into a Git repository by running: $ git pull https://github.com/zhangminglei/flink flink-9407-orc Alternatively you can review and apply these changes as the patch at: https://github.com/apache/flink/pull/6075.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #6075 commit d653d39f6cb74075874eb890cab36012d85dbecf Author: zhangmingleiDate: 2018-05-25T04:58:01Z [FLINK-9407] [hdfs connector] Support orc rolling sink writer ---