dariabezkorovaina commented on code in PR #30686:
URL: https://github.com/apache/beam/pull/30686#discussion_r1533664554


##########
learning/prompts/code-explanation/java/08_io_csv.md:
##########
@@ -0,0 +1,137 @@
+Prompt:
+What does this code do?
+
+```java
+public class WriteCsvFile {
+
+    @DefaultSchema(JavaFieldSchema.class)
+    public static class ExampleRecord implements Serializable {
+        public int id;
+        public String month;
+        public String amount;
+
+        public ExampleRecord() {
+        }
+
+        public ExampleRecord(int id, String month, String amount) {
+            this.id = id;
+            this.month = month;
+            this.amount = amount
+        }
+    }
+
+    public interface WriteCsvFileOptions extends PipelineOptions {
+
+        @Description("A file path to write CSV files to")
+        @Validation.Required
+        String getFilePath();
+
+        void setFilePath(String filePath);
+    }
+
+    public static void main(String[] args) {
+        WriteCsvFileOptions options =
+                PipelineOptionsFactory.fromArgs(args)
+                        .withValidation().as(WriteCsvFileOptions.class);
+
+        Pipeline p = Pipeline.create(options);
+
+        List<ExampleRecord> rows =
+            Arrays.asList(
+                new ExampleRecord(1, "January", "$1000"),
+                new ExampleRecord(2, "February", "$2000"),
+                new ExampleRecord(3, "March", "$3000"));
+
+        CSVFormat csvFormat =
+            CSVFormat.DEFAULT.withHeaderComments("CSV file created by Apache 
Beam")
+                .withCommentMarker('#');
+
+        p.apply("Create collection", Create.of(rows))
+            .apply(
+                "Write to CSV file",
+                    CsvIO.<ExampleRecord>write(options.getFilePathPrefix(), 
csvFormat)
+                        .withNumShards(1));
+        p.run();
+    }
+}
+
+```
+Response:

Review Comment:
   ```suggestion
   
   Response:
   ```



##########
learning/prompts/code-explanation/java/10_io_parquet.md:
##########
@@ -0,0 +1,154 @@
+Prompt:
+What does this code do?
+
+```java
+package parquet;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.reflect.ReflectData;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.io.parquet.ParquetIO;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReadParquetFile {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ReadParquetFile.class);
+
+    public static class ExampleRecord implements Serializable {
+        public static final String COLUMN_ID = "id";
+        public static final String COLUMN_MONTH = "month";
+        public static final String COLUMN_AMOUNT = "amount";
+
+        private int id;
+        private String month;
+        private String amount;
+    }
+
+    public interface ReadParquetFileOptions extends PipelineOptions {
+        @Description("A glob file pattern to read Parquet files from")
+        @Validation.Required
+        String getFilePattern();
+
+        void setFilePattern(String filePattern);
+    }
+
+    public static void main(String[] args) {
+        ReadParquetFileOptions options =
+            
PipelineOptionsFactory.fromArgs(args).withValidation().as(ReadParquetFileOptions.class);
+
+        Schema exampleRecordSchema = 
ReflectData.get().getSchema(ExampleRecord.class);
+
+        Pipeline p = Pipeline.create(options);
+
+        p.apply(
+                "Read from Parquet file",
+                ParquetIO.read(exampleRecordSchema)
+                    .withAvroDataModel(GenericData.get())
+                    .from(options.getFilePattern()))
+            .apply(
+                "Log records",
+                ParDo.of(
+                    new DoFn<GenericRecord, GenericRecord>() {
+                        @ProcessElement
+                        public void processElement(ProcessContext c) {
+                            GenericRecord record = 
Objects.requireNonNull(c.element());
+                            LOG.info(
+                                "Id = {}, Name = {}, Amount = {}",
+                                record.get(ExampleRecord.COLUMN_ID),
+                                record.get(ExampleRecord.COLUMN_MONTH),
+                                record.get(ExampleRecord.COLUMN_AMOUNT));
+                            c.output(record);
+                        }
+                    }));
+        p.run();
+    }
+}
+

Review Comment:
   ```suggestion
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to