You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ch...@apache.org on 2017/04/26 15:53:47 UTC

[1/2] incubator-carbondata git commit: add alter table example

Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 4b615d8cd -> 598bbd2b8


add alter table example

add alter table example

add alter table example

add alter table example

Just add AlterTableExample

Just add AlterTableExample

Just add AlterTableExample

Add AlterTableExamples


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

Branch: refs/heads/master
Commit: 1f9721f2b390304f69987b07594b6c8ea996c3aa
Parents: 4b615d8
Author: erlu <er...@erludeMacBook-Pro.local>
Authored: Wed Apr 26 10:54:19 2017 +0800
Committer: chenliang613 <ch...@huawei.com>
Committed: Wed Apr 26 23:52:33 2017 +0800

----------------------------------------------------------------------
 .../carbondata/examples/AlterTableExample.scala | 97 ++++++++++++++++++++
 1 file changed, 97 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/1f9721f2/examples/spark2/src/main/scala/org/apache/carbondata/examples/AlterTableExample.scala
----------------------------------------------------------------------
diff --git a/examples/spark2/src/main/scala/org/apache/carbondata/examples/AlterTableExample.scala b/examples/spark2/src/main/scala/org/apache/carbondata/examples/AlterTableExample.scala
new file mode 100644
index 0000000..1d01de9
--- /dev/null
+++ b/examples/spark2/src/main/scala/org/apache/carbondata/examples/AlterTableExample.scala
@@ -0,0 +1,97 @@
+/*
+ * 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 java.io.File
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.spark.sql.SparkSession
+
+
+object AlterTableExample {
+
+  def main(args: Array[String]): Unit = {
+
+    val rootPath = new File(this.getClass.getResource("/").getPath
+                            + "../../../..").getCanonicalPath
+
+    val storeLocation = s"$rootPath/examples/spark2/target/store"
+    val warehouse = s"$rootPath/examples/spark2/target/warehouse"
+    val metastoredb = s"$rootPath/examples/spark2/target/metastore_db"
+
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, "yyyy/MM/dd")
+
+    import org.apache.spark.sql.CarbonSession._
+
+    val spark = SparkSession
+      .builder()
+      .master("local")
+      .appName("AlterTableExample")
+      .config("spark.sql.warehouse.dir", warehouse)
+      .getOrCreateCarbonSession(storeLocation, metastoredb)
+
+    spark.sparkContext.setLogLevel("WARN")
+
+    spark.sql("DROP TABLE IF EXISTS carbon_table")
+    spark.sql("DROP TABLE IF EXISTS new_carbon_table")
+
+    spark.sql(
+      s"""
+         | CREATE TABLE carbon_table(
+         |    shortField short,
+         |    intField int,
+         |    bigintField long,
+         |    doubleField double,
+         |    stringField string,
+         |    timestampField timestamp,
+         |    decimalField decimal(18,2),
+         |    dateField date,
+         |    charField char(5),
+         |    floatField float,
+         |    complexData array<string>
+         | )
+         | STORED BY 'carbondata'
+         | TBLPROPERTIES('DICTIONARY_INCLUDE'='dateField, charField')
+       """.stripMargin)
+
+    // Alter table change data type
+    spark.sql("DESCRIBE FORMATTED carbon_table").show()
+    spark.sql("ALTER TABLE carbon_table CHANGE intField intField bigint").show()
+
+    // Alter table add columns
+    spark.sql("DESCRIBE FORMATTED carbon_table").show()
+    spark.sql("ALTER TABLE carbon_table ADD COLUMNS (newField String) " +
+              "TBLPROPERTIES ('DEFAULT.VALUE.newField'='def')").show()
+
+    // Alter table drop columns
+    spark.sql("DESCRIBE FORMATTED carbon_table").show()
+    spark.sql("ALTER TABLE carbon_table DROP COLUMNS (newField)").show()
+    spark.sql("DESCRIBE FORMATTED carbon_table").show()
+
+    // Alter table rename table name
+    spark.sql("SHOW TABLES").show()
+    spark.sql("ALTER TABLE carbon_table RENAME TO new_carbon_table").show()
+    spark.sql("SHOW TABLES").show()
+
+    spark.sql("DROP TABLE IF EXISTS carbon_table")
+    spark.sql("DROP TABLE IF EXISTS new_carbon_table")
+
+  }
+}


[2/2] incubator-carbondata git commit: [CARBONDATA-986] Add alter table example This closes #850

Posted by ch...@apache.org.
[CARBONDATA-986] Add alter table example This closes #850


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

Branch: refs/heads/master
Commit: 598bbd2b8a41ac0547799d0576f07e6b0da9888a
Parents: 4b615d8 1f9721f
Author: chenliang613 <ch...@huawei.com>
Authored: Wed Apr 26 23:53:20 2017 +0800
Committer: chenliang613 <ch...@huawei.com>
Committed: Wed Apr 26 23:53:20 2017 +0800

----------------------------------------------------------------------
 .../carbondata/examples/AlterTableExample.scala | 97 ++++++++++++++++++++
 1 file changed, 97 insertions(+)
----------------------------------------------------------------------