[ 
https://issues.apache.org/jira/browse/BEAM-4626?focusedWorklogId=115108&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-115108
 ]

ASF GitHub Bot logged work on BEAM-4626:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Jun/18 04:47
            Start Date: 24/Jun/18 04:47
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on a change in pull request 
#5748: [BEAM-4626] SQL text tables of raw lines
URL: https://github.com/apache/beam/pull/5748#discussion_r197628297
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/text/TextTable.java
 ##########
 @@ -0,0 +1,76 @@
+/*
+ * 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.beam.sdk.extensions.sql.meta.provider.text;
+
+import org.apache.beam.sdk.annotations.Internal;
+import org.apache.beam.sdk.extensions.sql.impl.schema.BaseBeamTable;
+import org.apache.beam.sdk.io.TextIO;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PBegin;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PDone;
+import org.apache.beam.sdk.values.Row;
+import org.apache.commons.csv.CSVFormat;
+
+/**
+ * {@link TextTable} is a {@link 
org.apache.beam.sdk.extensions.sql.BeamSqlTable} that reads text
+ * files and converts them according to the specified format.
+ *
+ * <p>Support formats are {@code "csv"} and {@code "lines"}.
+ *
+ * <p>{@link CSVFormat} itself has many dialects, check its javadoc for more 
info.
+ */
+@Internal
+public class TextTable extends BaseBeamTable {
+
+  private final PTransform<PCollection<String>, PCollection<Row>> 
readConverter;
+  private final PTransform<PCollection<Row>, PCollection<String>> 
writeConverter;
+  private final String filePattern;
+
+  /** Text table with the specified read and write transforms. */
+  public TextTable(
+      Schema schema,
+      String filePattern,
+      PTransform<PCollection<String>, PCollection<Row>> readConverter,
+      PTransform<PCollection<Row>, PCollection<String>> writeConverter) {
+    super(schema);
+    this.filePattern = filePattern;
+    this.readConverter = readConverter;
+    this.writeConverter = writeConverter;
+  }
+
+  public String getFilePattern() {
+    return filePattern;
+  }
+
+  @Override
+  public PCollection<Row> buildIOReader(PBegin begin) {
+    return begin
+        .apply("ReadTextFiles", TextIO.read().from(filePattern))
+        .apply("StringToRow", readConverter);
+  }
+
+  @Override
+  public PDone buildIOWriter(PCollection<Row> input) {
+    return input
+        .apply("RowToString", writeConverter)
+        .apply("WriteTextFiles", TextIO.write().withDelimiter(new 
char[]{}).to(filePattern));
 
 Review comment:
   @jkff @chamikaramj for context, this is why I modified TextIO to allow 
changing the delimiter - I actually just need to suppress it because it depends 
on the CSV format, and its added prior to writing.

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 115108)
    Time Spent: 0.5h  (was: 20m)

> Support text table format with a single column of the lines of the files
> ------------------------------------------------------------------------
>
>                 Key: BEAM-4626
>                 URL: https://issues.apache.org/jira/browse/BEAM-4626
>             Project: Beam
>          Issue Type: New Feature
>          Components: dsl-sql
>            Reporter: Kenneth Knowles
>            Assignee: Kenneth Knowles
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Today, SQL can read CSV and allows a {{format}} flag to control what CSV 
> variant is used. But to do easy things and write pure SQL jobs it would be 
> nice to just read the text file as a one-column table and do transformations 
> in SQL.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to