carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From QiangCai <...@git.apache.org>
Subject [GitHub] carbondata pull request #842: [CARBONDATA-937] Data loading for partition ta...
Date Thu, 11 May 2017 16:24:21 GMT
Github user QiangCai commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/842#discussion_r116036488
  
    --- Diff: integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala
---
    @@ -931,6 +954,82 @@ object CarbonDataRDDFactory {
     
       }
     
    +  /**
    +   * repartition the input data for partiton table.
    +   * @param sqlContext
    +   * @param dataFrame
    +   * @param carbonLoadModel
    +   * @return
    +   */
    +  private def repartitionInputData(sqlContext: SQLContext,
    +      dataFrame: Option[DataFrame],
    +      carbonLoadModel: CarbonLoadModel): RDD[Row] = {
    +    val carbonTable = carbonLoadModel.getCarbonDataLoadSchema.getCarbonTable
    +    val partitionInfo = carbonTable.getPartitionInfo(carbonTable.getFactTableName)
    +    val partitionColumn = partitionInfo.getColumnSchemaList.get(0).getColumnName
    +    val partitionColumnDataType = partitionInfo.getColumnSchemaList.get(0).getDataType
    +    val columns = carbonLoadModel.getCsvHeaderColumns
    +    var partitionColumnIndex = -1
    +    for (i <- 0 until columns.length) {
    +      if (partitionColumn.equals(columns(i))) {
    +        partitionColumnIndex = i
    +      }
    +    }
    +    if (partitionColumnIndex == -1) {
    +      throw new DataLoadingException("Partition column not found.")
    +    }
    +    // generate RDD[(K, V)] to use the partitionBy method of PairRDDFunctions
    +    val inputRDD: RDD[(String, Row)] = if (dataFrame.isDefined) {
    +      // input data from DataFrame
    +      val timestampFormatString = CarbonProperties.getInstance().getProperty(CarbonCommonConstants
    +        .CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)
    +      val timeStampFormat = new SimpleDateFormat(timestampFormatString)
    +      val dateFormatString = CarbonProperties.getInstance().getProperty(CarbonCommonConstants
    +        .CARBON_DATE_FORMAT, CarbonCommonConstants.CARBON_DATE_DEFAULT_FORMAT)
    +      val dateFormat = new SimpleDateFormat(dateFormatString)
    +      val delimiterLevel1 = carbonLoadModel.getComplexDelimiterLevel1
    +      val delimiterLevel2 = carbonLoadModel.getComplexDelimiterLevel2
    +      val serializationNullFormat =
    +        carbonLoadModel.getSerializationNullFormat.split(CarbonCommonConstants.COMMA,
2)(1)
    +      dataFrame.get.rdd.map { row =>
    +        (CarbonScalaUtil.getString(row.get(partitionColumnIndex), serializationNullFormat,
    +          delimiterLevel1, delimiterLevel2, timeStampFormat, dateFormat), row)
    +      }
    +    } else {
    +      // input data from files
    +      val hadoopConfiguration = new Configuration()
    +      CommonUtil.configureCSVInputFormat(hadoopConfiguration, carbonLoadModel)
    +      hadoopConfiguration.set(FileInputFormat.INPUT_DIR, carbonLoadModel.getFactFilePath)
    +      val columnCount = columns.length
    +      new NewHadoopRDD[NullWritable, StringArrayWritable](
    +        sqlContext.sparkContext,
    +        classOf[CSVInputFormat],
    +        classOf[NullWritable],
    +        classOf[StringArrayWritable],
    +        hadoopConfiguration)
    +        .map { currentRow =>
    +          val row = new StringArrayRow(new Array[String](columnCount))
    +          (currentRow._2.get()(partitionColumnIndex), row.setValues(currentRow._2.get()))
    +        }
    +    }
    +    if (partitionColumnDataType == DataType.STRING) {
    +      if (partitionInfo.getPartitionType == PartitionType.RANGE) {
    +        inputRDD.map { row => (ByteUtil.toBytes(row._1), row._2) }
    +          .partitionBy(PartitionFactory.getPartitioner(partitionInfo))
    --- End diff --
    
    fixed


---
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