imay commented on a change in pull request #1577: Support Segment for BetaRowset
URL: https://github.com/apache/incubator-doris/pull/1577#discussion_r310601871
 
 

 ##########
 File path: be/src/olap/rowset/segment_v2/segment_writer.cpp
 ##########
 @@ -0,0 +1,172 @@
+// 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.
+
+#include "olap/rowset/segment_v2/segment_writer.h"
+
+#include "env/env.h" // Env
+#include "olap/row_block.h" // RowBlock
+#include "olap/row_cursor.h" // RowCursor
+#include "olap/rowset/segment_v2/column_writer.h" // ColumnWriter
+#include "olap/short_key_index.h"
+
+namespace doris {
+namespace segment_v2 {
+
+const char* k_segment_magic = "D0R1";
+const uint32_t k_segment_magic_length = 4;
+
+SegmentWriter::SegmentWriter(std::string fname, uint32_t segment_id,
+                             const std::shared_ptr<TabletSchema>& 
tablet_schema,
+                             const SegmentWriterOptions& opts)
+        : _fname(std::move(fname)),
+        _segment_id(segment_id),
+        _tablet_schema(tablet_schema),
+        _opts(opts) {
+}
+
+SegmentWriter::~SegmentWriter() {
+    for (auto writer : _column_writers) {
+        delete writer;
+    }
+}
+
+Status SegmentWriter::init(uint32_t write_mbytes_per_sec) {
+    // create for write
+    RETURN_IF_ERROR(Env::Default()->new_writable_file(_fname, &_output_file));
+
+    uint32_t column_id = 0;
+    for (auto& column : _tablet_schema->columns()) {
+        ColumnMetaPB* column_meta = _footer.add_columns();
+        // TODO(zc): Do we need this column_id??
+        column_meta->set_column_id(column_id++);
+        column_meta->set_unique_id(column.unique_id());
+        bool is_nullable = column.is_nullable();
+        column_meta->set_is_nullable(is_nullable);
+
+        // TODO(zc): we can add type_info into TabletColumn?
+        const TypeInfo* type_info = get_type_info(column.type());
+        DCHECK(type_info != nullptr);
+
+        ColumnWriterOptions opts;
+        std::unique_ptr<ColumnWriter> writer(new ColumnWriter(opts, type_info, 
is_nullable, _output_file.get()));
 
 Review comment:
   `ColumnWirterOptions` contains options. If there is no other set, this also 
can work. However I think type_info and is_nullable is what we really need, so 
I'd like put these out of options

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to