carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jack...@apache.org
Subject [1/2] incubator-carbondata git commit: add example
Date Wed, 05 Oct 2016 12:43:55 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 08bec66c3 -> dbf50ab4b


add example

rebase


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

Branch: refs/heads/master
Commit: 86d0b6dfadc56dfdbd8428a78a3a0c1a13b4734c
Parents: 08bec66
Author: jackylk <jacky.likun@huawei.com>
Authored: Fri Sep 23 01:27:04 2016 -0700
Committer: jackylk <jacky.likun@huawei.com>
Committed: Wed Oct 5 20:42:54 2016 +0800

----------------------------------------------------------------------
 .../carbondata/examples/DirectSQLExample.scala  | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/86d0b6df/examples/src/main/scala/org/apache/carbondata/examples/DirectSQLExample.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/carbondata/examples/DirectSQLExample.scala
b/examples/src/main/scala/org/apache/carbondata/examples/DirectSQLExample.scala
new file mode 100644
index 0000000..2553e8c
--- /dev/null
+++ b/examples/src/main/scala/org/apache/carbondata/examples/DirectSQLExample.scala
@@ -0,0 +1,44 @@
+/*
+ * 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.spark.sql.SQLContext
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.examples.util.ExampleUtils
+
+/**
+ * This example needs Spark 1.6 or later version to run
+ */
+object DirectSQLExample {
+
+  def main(args: Array[String]) {
+    val cc = ExampleUtils.createCarbonContext("DatasourceExample")
+    ExampleUtils.writeSampleCarbonFile(cc, "table1")
+
+    // Use SQLContext to read CarbonData files without creating table
+    val sqlContext = new SQLContext(cc.sparkContext)
+    sqlContext.sql(
+      s"""
+        | SELECT c1, c2, count(*)
+        | FROM carbondata.`${cc.storePath}/${CarbonCommonConstants.DATABASE_DEFAULT_NAME}/table1`
+        | WHERE c3 > 100
+        | GROUP BY c1, c2
+      """.stripMargin).show
+  }
+}


Mime
View raw message