You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/11/21 18:57:53 UTC

[GitHub] [incubator-druid] ccaominh commented on a change in pull request #8915: add TsvInputFormat

ccaominh commented on a change in pull request #8915: add TsvInputFormat
URL: https://github.com/apache/incubator-druid/pull/8915#discussion_r349260837
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/data/input/impl/SeparateValueInputFormat.java
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.druid.data.input.impl;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import org.apache.druid.data.input.InputEntity;
+import org.apache.druid.data.input.InputEntityReader;
+import org.apache.druid.data.input.InputFormat;
+import org.apache.druid.data.input.InputRowSchema;
+import org.apache.druid.indexer.Checks;
+import org.apache.druid.indexer.Property;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+public class SeparateValueInputFormat implements InputFormat
+{
+  private final String listDelimiter;
+  private final List<String> columns;
+  private final boolean findColumnsFromHeader;
+  private final int skipHeaderRows;
+  private final String seperator;
+
+  @JsonCreator
+  public SeparateValueInputFormat(
+      @JsonProperty("columns") @Nullable List<String> columns,
+      @JsonProperty("listDelimiter") @Nullable String listDelimiter,
+      @Deprecated @JsonProperty("hasHeaderRow") @Nullable Boolean hasHeaderRow,
+      @JsonProperty("findColumnsFromHeader") @Nullable Boolean findColumnsFromHeader,
+      @JsonProperty("skipHeaderRows") int skipHeaderRows,
+      String seperator
+  )
+  {
+    this.listDelimiter = listDelimiter;
+    this.columns = columns == null ? Collections.emptyList() : columns;
+    //noinspection ConstantConditions
+    this.findColumnsFromHeader = Checks.checkOneNotNullOrEmpty(
+        ImmutableList.of(
+            new Property<>("hasHeaderRow", hasHeaderRow),
+            new Property<>("findColumnsFromHeader", findColumnsFromHeader)
+        )
+    ).getValue();
+    this.skipHeaderRows = skipHeaderRows;
+    this.seperator = seperator;
+
+    if (!this.columns.isEmpty()) {
+      for (String column : this.columns) {
+        Preconditions.checkArgument(
+            !column.contains("tab".equals(seperator) ? "\t" : ","),
 
 Review comment:
   What do you think of using something like the `AbstractFlatTextFormatParser.FlatTextFormat` enum for this instead of hard-coding strings?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org