You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by sounakr <gi...@git.apache.org> on 2018/04/25 12:03:12 UTC

[GitHub] carbondata pull request #2226: [CARBONDATA-2384] SDK support write/read data...

Github user sounakr commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2226#discussion_r184033067
  
    --- Diff: examples/spark2/src/main/scala/org/apache/carbondata/sdk/SDkWriteS3Example.scala ---
    @@ -0,0 +1,124 @@
    +/*
    + * 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.sdk
    +
    +import org.slf4j.{Logger, LoggerFactory}
    +
    +import org.apache.carbondata.core.metadata.datatype.DataTypes
    +import org.apache.carbondata.sdk.file.{CarbonReader, CarbonWriter, Field, Schema}
    +
    +/**
    + * Generate data and write data to S3 by SDK, no spark
    + */
    +object SDKWriteS3Example {
    +
    +  // scalastyle:off println
    +  /**
    +   * This example demonstrate usage of
    +   *
    +   * @param args require three parameters "Access-key" "Secret-key"
    +   *             "s3-endpoint", other is optional
    +   */
    +  def main(args: Array[String]) {
    +    val logger: Logger = LoggerFactory.getLogger(this.getClass)
    +    if (args.length < 2 || args.length > 6) {
    +      logger.error("Usage: java CarbonS3Example: <access-key> <secret-key>" +
    +        "<s3-endpoint> [table-path-on-s3] [number-of-rows] [persistSchema]")
    +      System.exit(0)
    +    }
    +
    +    val path = if (args.length > 3) {
    +      args(3)
    +    } else {
    +      "s3a://sdk/WriterOutput"
    +    }
    +
    +    val num = if (args.length > 4) {
    +      Integer.parseInt(args(4))
    +    } else {
    +      3
    +    }
    +
    +    val persistSchema = if (args.length > 5) {
    +      if (args(5).equalsIgnoreCase("true")) {
    +        true
    +      } else {
    +        false
    +      }
    +    } else {
    +      true
    +    }
    +
    +    // getCanonicalPath gives path with \, so code expects /.
    +    val writerPath = path.replace("\\", "/");
    +
    +    val fields: Array[Field] = new Array[Field](3)
    +    fields(0) = new Field("name", DataTypes.STRING)
    +    fields(1) = new Field("age", DataTypes.INT)
    +    fields(2) = new Field("height", DataTypes.DOUBLE)
    +
    +    try {
    +      val builder = CarbonWriter.builder()
    +        .withSchema(new Schema(fields))
    +        .outputPath(writerPath)
    +        .isTransactionalTable(true)
    --- End diff --
    
    Please write test cases for Non Transactional table in reader and writer.


---