carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From QiangCai <...@git.apache.org>
Subject [GitHub] incubator-carbondata pull request #751: [CARBONDATA-816] Added Example for H...
Date Fri, 07 Apr 2017 11:48:44 GMT
Github user QiangCai commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/751#discussion_r110371979
  
    --- Diff: integration/hive/src/main/scala/org/apache/carbondata/hiveexample/HiveExample.scala
---
    @@ -0,0 +1,146 @@
    +/*
    + * 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.hiveexample
    +
    +import java.io.File
    +import java.sql.{DriverManager, ResultSet, SQLException, Statement}
    +
    +import org.apache.spark.sql.SparkSession
    +
    +import org.apache.carbondata.common.logging.LogServiceFactory
    +import org.apache.carbondata.hive.server.HiveEmbeddedServer2
    +
    +object HiveExample {
    +
    +  private val driverName: String = "org.apache.hive.jdbc.HiveDriver"
    +
    +  /**
    +   * @param args
    +   * @throws SQLException
    +   */
    +  @throws[SQLException]
    +  def main(args: Array[String]) {
    +    val rootPath = new File(this.getClass.getResource("/").getPath
    +                            + "../../../..").getCanonicalPath
    +    val warehouse = s"$rootPath/integration/hive/target/warehouse"
    +    val metaStore_Db = s"$rootPath/integration/hive/target/carbon_metaStore_db"
    +    val logger = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
    +
    +    import org.apache.spark.sql.CarbonSession._
    +
    +    val carbon = SparkSession
    +      .builder()
    +      .master("local")
    +      .appName("HiveExample")
    +      .config("carbon.sql.warehouse.dir", warehouse).enableHiveSupport()
    +      .getOrCreateCarbonSession(
    +        "hdfs://localhost:54310/opt/carbonStore", metaStore_Db)
    +
    +    carbon.sql("""drop table if exists hive_carbon_example""".stripMargin)
    +
    +    carbon
    +      .sql(
    +        """create table hive_carbon_example (id int,name string,salary double) stored
by
    +          |'carbondata' """
    +          .stripMargin)
    +
    +    carbon.sql(
    +      s"""
    +           LOAD DATA LOCAL INPATH '$rootPath/integration/hive/src/main/resources/data.csv'
into
    +           table
    +         hive_carbon_example
    +           """)
    +    carbon.sql("select * from hive_carbon_example").show()
    +
    +    carbon.stop()
    +
    +    try {
    +      Class.forName(driverName)
    +    }
    +    catch {
    +      case classNotFoundException: ClassNotFoundException =>
    +        classNotFoundException.printStackTrace()
    +    }
    +
    +    val hiveEmbeddedServer2 = new HiveEmbeddedServer2()
    +    hiveEmbeddedServer2.start()
    +    val port = hiveEmbeddedServer2.getFreePort
    +    val con = DriverManager.getConnection(s"jdbc:hive2://localhost:$port/default", "",
"")
    +    val stmt: Statement = con.createStatement
    +
    +    logger.info(s"============HIVE CLI IS STARTED ON PORT $port ==============")
    +
    +    stmt
    +      .execute(s"ADD JAR $rootPath/assembly/target/scala-2.11/carbondata_2.11-1.1" +
    --- End diff --
    
    check whether jar file is exists or not


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message