carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [1/2] incubator-carbondata git commit: add data update and deletion example
Date Thu, 19 Jan 2017 17:05:27 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 68a16d2c9 -> ee9562414


add data update and deletion example

add data update and deletion example

fix comments

fix comments

fix ci issues


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

Branch: refs/heads/master
Commit: 6583d2eb7cb72d1448fabcdd489af36738934198
Parents: 68a16d2
Author: chenliang613 <chenliang613@huawei.com>
Authored: Mon Jan 16 16:07:09 2017 +0800
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Thu Jan 19 22:33:27 2017 +0530

----------------------------------------------------------------------
 .../spark/src/main/resources/data_update.csv    |  11 ++
 .../examples/DataUpdateDeleteExample.scala      | 117 +++++++++++++++++++
 2 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6583d2eb/examples/spark/src/main/resources/data_update.csv
----------------------------------------------------------------------
diff --git a/examples/spark/src/main/resources/data_update.csv b/examples/spark/src/main/resources/data_update.csv
new file mode 100644
index 0000000..3f72e00
--- /dev/null
+++ b/examples/spark/src/main/resources/data_update.csv
@@ -0,0 +1,11 @@
+ID,country,name,phonetype,serialname,salary
+1,france,bbb1,phone197,ASD69643,25000
+2,france,bbb2,phone756,ASD42892,25001
+3,france,bbb3,phone1904,ASD37014,25002
+4,france,bbb4,phone2435,ASD66902,25003
+5,france,bbb5,phone2441,ASD90633,25004
+6,germany,bbb6,phone294,ASD59961,25005
+7,germany,bbb7,phone610,ASD14875,25006
+8,germany,bbb8,phone1848,ASD57308,25007
+9,germany,bbb9,phone706,ASD86717,25008
+10,germany,bbb10,phone685,ASD30505,25009
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6583d2eb/examples/spark/src/main/scala/org/apache/carbondata/examples/DataUpdateDeleteExample.scala
----------------------------------------------------------------------
diff --git a/examples/spark/src/main/scala/org/apache/carbondata/examples/DataUpdateDeleteExample.scala
b/examples/spark/src/main/scala/org/apache/carbondata/examples/DataUpdateDeleteExample.scala
new file mode 100644
index 0000000..a6c35cc
--- /dev/null
+++ b/examples/spark/src/main/scala/org/apache/carbondata/examples/DataUpdateDeleteExample.scala
@@ -0,0 +1,117 @@
+/*
+ * 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
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.examples.util.ExampleUtils
+
+object DataUpdateDeleteExample {
+
+  def main(args: Array[String]) {
+    val cc = ExampleUtils.createCarbonContext("DataUpdateDeleteExample")
+    val testData = ExampleUtils.currentPath + "/src/main/resources/data.csv"
+    val testData1 = ExampleUtils.currentPath + "/src/main/resources/data_update.csv"
+
+    // Specify timestamp format based on raw data
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, "yyyy/MM/dd")
+
+    cc.sql("DROP TABLE IF EXISTS t3")
+    cc.sql("DROP TABLE IF EXISTS update_table")
+
+    // Create table, 6 dimensions, 1 measure
+    cc.sql("""
+           CREATE TABLE IF NOT EXISTS t3
+           (ID Int, date Timestamp, country String,
+           name String, phonetype String, serialname char(10), salary Int)
+           STORED BY 'carbondata'
+           """)
+
+    cc.sql(s"""
+           LOAD DATA LOCAL INPATH '$testData' INTO TABLE t3
+           """)
+
+    // 1.Update data with simple SET
+    cc.sql("""
+           SELECT * FROM t3 ORDER BY ID
+           """).show()
+
+    // Update data where salary < 15003
+    cc.sql("""
+           UPDATE t3 SET (t3.country) = ('india') WHERE t3.salary < 15003
+           """).show()
+    cc.sql("""
+           UPDATE t3 SET (t3.salary) = (t3.salary + 9) WHERE t3.name = 'aaa1'
+           """).show()
+
+    // Query data again after the above update
+    cc.sql("""
+           SELECT * FROM t3 ORDER BY ID
+           """).show()
+
+    // 2.Update data with subquery result SET
+    cc.sql("""
+           CREATE TABLE IF NOT EXISTS update_table
+           (ID Int, country String,
+           name String, phonetype String, serialname char(10), salary Int)
+           STORED BY 'carbondata'
+           """)
+
+    cc.sql(s"""
+           LOAD DATA LOCAL INPATH '$testData1' INTO TABLE update_table
+           """)
+
+    cc.sql("""
+         UPDATE t3
+         SET (t3.country, t3.name) = (SELECT u.country, u.name FROM update_table u WHERE
u.id = 5)
+         WHERE t3.id < 5""").show()
+
+    // Query data again after the above update
+    cc.sql("""
+           SELECT * FROM t3 ORDER BY ID
+           """).show()
+
+    // 3.Update data with join query result SET
+    cc.sql("""
+         UPDATE t3
+         SET (t3.country, t3.salary) =
+         (SELECT u.country, f.salary FROM update_table u FULL JOIN update_table f
+         WHERE u.id = 8 and f.id=6) WHERE t3.id >6""").show()
+
+    // Query data again after the above update
+    cc.sql("""
+           SELECT * FROM t3 ORDER BY ID
+           """).show()
+
+    // 4.Delete data where salary > 15005
+    cc.sql("""
+           DELETE FROM t3 WHERE salary > 15005
+           """).show()
+
+    // Query data again after delete data
+    cc.sql("""
+           SELECT * FROM t3 ORDER BY ID
+           """).show()
+
+    // Drop table
+    cc.sql("DROP TABLE IF EXISTS t3")
+    cc.sql("DROP TABLE IF EXISTS update_table")
+  }
+
+}


Mime
View raw message