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

    
https://github.com/apache/incubator-carbondata/pull/653#discussion_r105920583
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/CarbonDictionaryDecoder.scala
 ---
    @@ -200,6 +201,123 @@ case class CarbonDictionaryDecoder(
         }
       }
     
    +  override def doConsume(ctx: CodegenContext, input: Seq[ExprCode], row: 
ExprCode): String = {
    +
    +    val storePath = CarbonEnv.get.carbonMetastore.storePath
    +    val absoluteTableIdentifiers = relations.map { relation =>
    +      val carbonTable = 
relation.carbonRelation.carbonRelation.metaData.carbonTable
    +      (carbonTable.getFactTableName, 
carbonTable.getAbsoluteTableIdentifier)
    +    }.toMap
    +
    +    if (isRequiredToDecode) {
    +      val cacheProvider: CacheProvider = CacheProvider.getInstance
    +      val forwardDictionaryCache: Cache[DictionaryColumnUniqueIdentifier, 
Dictionary] =
    +        cacheProvider.createCache(CacheType.FORWARD_DICTIONARY, storePath)
    +      val dicts: Seq[ForwardDictionaryWrapper] = 
getDictionaryWrapper(absoluteTableIdentifiers,
    +        forwardDictionaryCache, storePath)
    +
    +      val exprs = child.output.map(x =>
    +        ExpressionCanonicalizer.execute(BindReferences.bindReference(x, 
child.output)))
    +      ctx.currentVars = input
    +      val resultVars = exprs.zipWithIndex.map { e =>
    +        if (dicts(e._2) != null) {
    +          val ev = e._1.genCode(ctx)
    +          val value = ctx.freshName("value")
    +          val valueIntern = ctx.freshName("valueIntern")
    +          val isNull = ctx.freshName("isNull")
    +          val dictsRef = ctx.addReferenceObj("dictsRef", dicts(e._2))
    +          var code =
    +            s"""
    +               |${ev.code}
    +             """.stripMargin
    +          code +=
    +            s"""
    +             |boolean $isNull = false;
    +             |byte[] $valueIntern = 
$dictsRef.getDictionaryValueForKeyInBytes(${ ev.value });
    +             |if 
(java.util.Arrays.equals(org.apache.carbondata.core.constants
    +             |.CarbonCommonConstants.MEMBER_DEFAULT_VAL_ARRAY, 
$valueIntern)) {
    +             |  $isNull = true;
    +             |}
    +             """.stripMargin
    +
    +            val caseCode = getDictionaryColumnIds(e._2)._3 match {
    +              case DataType.INT =>
    +                s"""
    +                   |int $value = Integer.parseInt(new String($valueIntern,
    +                   
|org.apache.carbondata.core.constants.CarbonCommonConstants
    +                   |.DEFAULT_CHARSET_CLASS));
    +                 """.stripMargin
    +              case DataType.SHORT =>
    +                s"""
    +                   |short $value =
    +                   |Short.parseShort(new String($valueIntern,
    +                   
|org.apache.carbondata.core.constants.CarbonCommonConstants
    +                   |.DEFAULT_CHARSET_CLASS));
    +                 """.stripMargin
    +              case DataType.DOUBLE =>
    +                s"""
    +                   |double $value =
    +                   |Double.parseDouble(new String($valueIntern,
    +                   
|org.apache.carbondata.core.constants.CarbonCommonConstants
    +                   |.DEFAULT_CHARSET_CLASS));
    +                 """.stripMargin
    +              case DataType.LONG =>
    +                s"""
    +                   |long $value =
    +                   |Long.parseLong(new String($valueIntern,
    +                   
|org.apache.carbondata.core.constants.CarbonCommonConstants
    +                   |.DEFAULT_CHARSET_CLASS));
    +                 """.stripMargin
    +              case DataType.DECIMAL =>
    +                s"""
    +                   |org.apache.spark.sql.types.Decimal $value =
    +                   |Decimal.apply(new java.math.BigDecimal(
    +                   |new String($valueIntern, 
org.apache.carbondata.core.constants
    +                   |.CarbonCommonConstants.DEFAULT_CHARSET_CLASS)));
    +                 """.stripMargin
    +              case _ =>
    +                s"""
    +                   | UTF8String $value = 
UTF8String.fromBytes($valueIntern);
    +                 """.stripMargin
    +            }
    +          code +=
    +            s"""
    +               |$caseCode
    +             """.stripMargin
    --- End diff --
    
    simplify it in one line


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to