Static and dynamic partition loads in Hive table through Spark

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Static and dynamic partition loads in Hive table through Spark

Mich Talebzadeh
Hi,

This is something that I am banging my head to explain someone so hence this question

There is an underlying Hive that which is populated reading an XML file through Spark.

The table in Hive is defined as follows with two partition columns

      var sqltext =
      s"""
        CREATE TABLE IF NOT EXISTS ${broadcastStagingConfig.broadcastTable} (
           partyId STRING
         , phoneNumber STRING
        )
        PARTITIONED BY (
           broadcastId STRING
        ,  brand STRING
        )
        STORED AS PARQUET
        """
    spark.sql(sqltext)
 
Then we populate table as follows

    sqltext =
      s"""
        INSERT INTO TABLE ${broadcastStagingConfig.broadcastTable} PARTITION (broadcastId = ${broadcastStagingConfig.broadcastValue},  brand)
        SELECT
          ocis_mrg_pty_id AS partyId
        , target_mobile_no AS phoneNumber
                      , brand
        FROM tmp
       WHERE
          length(target_mobile_no) = 10
       AND
          substring(target_mobile_no,1,1) = "7"
        """
    spark.sql(sqltext)

So back to partitioning, Partition column broascastId is a constant value for this particular insert of rows (all rows share the same value). That is its value is known before actually reading the XML rows so I qualify it as static partition. However, the column brand is  a dynamic partition as potentially it can have a range of values and which brand partition it will belong to will only be known after the row is inserted. 

Is this assertion correct?

Thanks,

 Dr Mich Talebzadeh

 

LinkedIn  https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw

 

http://talebzadehmich.wordpress.com


Disclaimer: Use it at your own risk. Any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on this email's technical content is explicitly disclaimed. The author will in no case be liable for any monetary damages arising from such loss, damage or destruction.