carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jack...@apache.org
Subject carbondata git commit: [CARBONDATA-2392] Add close method for CarbonReader
Date Thu, 03 May 2018 08:18:03 GMT
Repository: carbondata
Updated Branches:
  refs/heads/master 380473b40 -> f7c0670cd


[CARBONDATA-2392] Add close method for CarbonReader

This closes #2221


Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/f7c0670c
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/f7c0670c
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/f7c0670c

Branch: refs/heads/master
Commit: f7c0670cd15267d59e47446937e952374624f6df
Parents: 380473b
Author: xubo245 <601450868@qq.com>
Authored: Tue Apr 24 17:59:42 2018 +0800
Committer: Jacky Li <jacky.likun@qq.com>
Committed: Thu May 3 16:17:48 2018 +0800

----------------------------------------------------------------------
 .../examples/sdk/CarbonReaderExample.java       | 76 ++++++++++++++++++++
 .../carbondata/examples/sdk/SDKS3Example.java   |  3 +-
 .../carbondata/sdk/file/CarbonReader.java       |  9 +++
 .../carbondata/sdk/file/CarbonReaderTest.java   |  1 +
 4 files changed, 87 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/f7c0670c/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/CarbonReaderExample.java
----------------------------------------------------------------------
diff --git a/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/CarbonReaderExample.java
b/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/CarbonReaderExample.java
new file mode 100644
index 0000000..8ea8604
--- /dev/null
+++ b/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/CarbonReaderExample.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.carbondata.examples.sdk;
+
+import java.io.File;
+
+import org.apache.commons.io.FileUtils;
+
+import org.apache.carbondata.core.metadata.datatype.DataTypes;
+import org.apache.carbondata.sdk.file.CarbonReader;
+import org.apache.carbondata.sdk.file.CarbonWriter;
+import org.apache.carbondata.sdk.file.Field;
+import org.apache.carbondata.sdk.file.Schema;
+
+
+/**
+ * Example fo CarbonReader with close method
+ * After readNextRow of CarbonReader, User should close the reader,
+ * otherwise main will continue run some time
+ */
+public class CarbonReaderExample {
+    public static void main(String[] args) {
+        String path = "./testWriteFiles";
+        try {
+            FileUtils.deleteDirectory(new File(path));
+
+            Field[] fields = new Field[2];
+            fields[0] = new Field("name", DataTypes.STRING);
+            fields[1] = new Field("age", DataTypes.INT);
+
+            CarbonWriter writer = CarbonWriter.builder()
+                    .withSchema(new Schema(fields))
+                    .isTransactionalTable(true)
+                    .outputPath(path)
+                    .persistSchemaFile(true)
+                    .buildWriterForCSVInput();
+
+            for (int i = 0; i < 10; i++) {
+                writer.write(new String[]{"robot" + (i % 10), String.valueOf(i)});
+            }
+            writer.close();
+
+            // Read data
+            CarbonReader reader = CarbonReader
+                    .builder(path, "_temp")
+                    .projection(new String[]{"name", "age"})
+                    .build();
+
+            System.out.println("\nData:");
+            while (reader.hasNext()) {
+                Object[] row = (Object[]) reader.readNextRow();
+                System.out.println(row[0] + " " + row[1]);
+            }
+            System.out.println("\nFinished");
+            reader.close();
+            FileUtils.deleteDirectory(new File(path));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f7c0670c/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/SDKS3Example.java
----------------------------------------------------------------------
diff --git a/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/SDKS3Example.java
b/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/SDKS3Example.java
index 60aa1f8..02247cb 100644
--- a/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/SDKS3Example.java
+++ b/examples/spark2/src/main/java/org/apache/carbondata/examples/sdk/SDKS3Example.java
@@ -97,7 +97,6 @@ public class SDKS3Example {
             i++;
         }
         System.out.println("\nFinished");
-        // TODO
-        //        reader.close();
+        reader.close();
     }
 }

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f7c0670c/store/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonReader.java
----------------------------------------------------------------------
diff --git a/store/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonReader.java b/store/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonReader.java
index 716ec2a..c9cd8f5 100644
--- a/store/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonReader.java
+++ b/store/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonReader.java
@@ -104,4 +104,13 @@ public class CarbonReader<T> {
     SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
     return schemaConverter.fromExternalToWrapperTableInfo(tableInfo, "", "", "");
   }
+
+  /**
+   * Close reader
+   *
+   * @throws IOException
+   */
+  public void close() throws IOException {
+    this.currentReader.close();
+  }
 }

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f7c0670c/store/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
----------------------------------------------------------------------
diff --git a/store/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
b/store/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
index f026499..08d6e52 100644
--- a/store/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
+++ b/store/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
@@ -64,6 +64,7 @@ public class CarbonReaderTest {
     }
     Assert.assertEquals(i, 100);
 
+    reader.close();
     FileUtils.deleteDirectory(new File(path));
   }
 


Mime
View raw message