snleee commented on a change in pull request #4737: Druid-Pinot Segment 
Converter Tool
URL: https://github.com/apache/incubator-pinot/pull/4737#discussion_r346574399
 
 

 ##########
 File path: 
contrib/pinot-druid-migration/src/main/java/org/apache/pinot/druid/tools/DruidToPinotSegmentConverter.java
 ##########
 @@ -0,0 +1,77 @@
+/**
+ * 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.pinot.druid.tools;
+
+import com.google.common.base.Preconditions;
+import java.io.File;
+import org.apache.pinot.common.data.Schema;
+import org.apache.pinot.core.indexsegment.generator.SegmentGeneratorConfig;
+import 
org.apache.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.druid.data.readers.DruidSegmentRecordReader;
+
+
+/**
+ * The DruidToPinotSegmentConverter is a CLI tool that converts a Druid 
segment to a Pinot segment.
+ */
+public class DruidToPinotSegmentConverter {
+  private static String _schemaFilePath;
+  private static String _druidSegmentPath;
+  private static String _outPath;
+  private static String _segmentName;
+  private static String _tableName;
+
+  // TODO: Change implementation to use the Command framework like the 
CreateSegmentCommand
+  public static void convertSegment()
+      throws Exception {
+    File segment = new File(_druidSegmentPath);
+    Schema schema = Schema.fromFile(new File(_schemaFilePath));
+
+    final SegmentGeneratorConfig segmentGeneratorConfig = new 
SegmentGeneratorConfig();
+    segmentGeneratorConfig.setDataDir(_druidSegmentPath);
+    segmentGeneratorConfig.setOutDir(_outPath);
+    segmentGeneratorConfig.setOverwrite(true);
+    segmentGeneratorConfig.setTableName(_tableName);
+    segmentGeneratorConfig.setSegmentName(_segmentName);
+    segmentGeneratorConfig.setSchemaFile(_schemaFilePath);
+    segmentGeneratorConfig.setSchema(schema);
+
+    final SegmentIndexCreationDriverImpl driver = new 
SegmentIndexCreationDriverImpl();
+    SegmentGeneratorConfig config = new 
SegmentGeneratorConfig(segmentGeneratorConfig);
+    DruidSegmentRecordReader recordReader = new 
DruidSegmentRecordReader(segment, segmentGeneratorConfig.getSchema());
+    driver.init(config, recordReader);
+    driver.build();
+  }
+
+  public static void main(String[] args) {
+    // Arg format is segmentPath, outDir, schemaPath, segmentName, tableName
+    Preconditions.checkArgument(args.length == 5);
+    _druidSegmentPath = args[0];
+    _outPath = args[1];
+    _schemaFilePath = args[2];
+    _segmentName = args[3];
+    _tableName = args[4];
+
+    try {
+      convertSegment();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+
 
 Review comment:
   Remove the line

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to