<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayush Saxena on Medium]]></title>
        <description><![CDATA[Stories by Ayush Saxena on Medium]]></description>
        <link>https://medium.com/@ayushtkn?source=rss-fcf2a5c2e85f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0MaN3qWIOoDWwrJKIOOmug.jpeg</url>
            <title>Stories by Ayush Saxena on Medium</title>
            <link>https://medium.com/@ayushtkn?source=rss-fcf2a5c2e85f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:41:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushtkn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cloud-Native Apache Hive: A Deep Dive into the New Kubernetes Operator, Autoscaling, and…]]></title>
            <link>https://medium.com/@ayushtkn/cloud-native-apache-hive-a-deep-dive-into-the-new-kubernetes-operator-autoscaling-and-6d3e4427121a?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d3e4427121a</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[helm-chart]]></category>
            <category><![CDATA[apache-iceberg]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Tue, 23 Jun 2026 08:02:19 GMT</pubDate>
            <atom:updated>2026-06-23T08:02:19.130Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cloud-Native Apache Hive: A Deep Dive into the New Kubernetes Operator, Autoscaling, and Multi-Tenancy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qz7trNk8aYt9jVwJ3j2Bgw.png" /><figcaption>Apache Hive Kubernetes Operator</figcaption></figure><p>Apache Hive has taken a massive leap forward in its cloud-native journey. With the introduction of the new Kubernetes Operator, managing a Highly Available (HA) Apache Hive cluster on Kubernetes is no longer an exercise in writing endless YAML manifests. It is now entirely declarative.</p><p>A single HiveCluster Custom Resource Definition (CRD) now manages the entire lifecycle of the Hive Metastore (HMS), HiveServer2 (HS2), LLAP daemons, and Tez Application Masters (TezAM).</p><p>But the operator goes far beyond simple deployment. By orchestrating the latest releases of Apache Hive, it unlocks <strong>native zero-dependency autoscaling</strong>, <strong>scale-to-zero hibernation</strong>, <strong>multi-tenant LLAP clusters</strong>, and out-of-the-box <strong>Apache Iceberg support</strong>.</p><p>In this deep dive, we will explore the theory behind these features, explain the CRD configuration parameters in detail, and provide real-world examples for deploying via Helm.</p><h3>1. Prerequisites &amp; Dependencies</h3><p>Before deploying the Hive Operator, you need a few core dependencies in your Kubernetes cluster.</p><ul><li><strong>Database:</strong> A backend database for the Hive Metastore. The operator supports PostgreSQL, MySQL, Derby, Oracle, and MSSQL. <em>(Note: You can also skip deploying a database entirely and connect to an existing external HMS).</em></li><li><strong>ZooKeeper:</strong> Required for LLAP service discovery and Tez session registries.</li><li><strong>Storage:</strong> Any Hadoop-compatible file system (Apache Ozone, AWS S3, GCS, ABFS, HDFS).</li></ul><h3>2. Storage Configurations, Hadoop Overrides, and External HMS</h3><p>The Hive Operator is completely storage-agnostic. It seamlessly integrates with any Hadoop-compatible file system by injecting overrides directly into core-site.xml and mounting the necessary credentials.</p><h3>Storage &amp; Native Hive Overrides</h3><p>You can pass custom properties to core-site.xml using coreSiteOverrides, and to hive-site.xml or llap-daemon-site.xml using configOverrides.</p><pre># values.yaml<br>cluster:<br>  database:<br>    type: postgres<br>    url: &quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot;<br>    driver: &quot;org.postgresql.Driver&quot;<br>    username: hive<br>    passwordSecretRef:<br>      name: hive-db-secret<br>      key: password<br>    driverJarUrl: &quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot;<br>  zookeeper:<br>    quorum: &quot;zookeeper:2181&quot;<br>  storage:<br>    coreSiteOverrides:<br>      fs.defaultFS: &quot;s3a://hive&quot;<br>      fs.s3a.endpoint: &quot;http://ozone-s3g-rest:9878&quot;<br>      fs.s3a.path.style.access: &quot;true&quot;<br>    envVars:<br>      - name: HADOOP_OPTIONAL_TOOLS<br>        value: &quot;hadoop-aws&quot;<br>      - name: AWS_ACCESS_KEY_ID<br>        value: &quot;ozone&quot;<br>      - name: AWS_SECRET_ACCESS_KEY<br>        value: &quot;ozone&quot;<br>  # Native Hive Overrides<br>  hiveServer2:<br>    replicas: 2<br>    configOverrides:<br>      hive.server2.enable.doAs: &quot;false&quot;</pre><h3>External Metastore (Bring Your Own HMS)</h3><p>If your organization already has a central Hive Metastore running elsewhere, you don’t have to deploy a new one. You can instruct the operator to skip the HMS deployment and point HiveServer2 directly to your existing endpoint by setting metastore.enabled: false and providing an externalUri:</p><pre>cluster:<br>  database: {} # Not needed when metastore is external<br>  zookeeper:<br>    quorum: &quot;zookeeper:2181&quot;<br>  metastore:<br>    enabled: false<br>    externalUri: &quot;thrift://my-external-metastore.company.internal:9083&quot;</pre><h3>3. Intelligent Autoscaling: Zero-Dependency Elasticity</h3><p>In the cloud, provisioning for “peak load” means you are burning money at 3:00 AM when your cluster is idle.</p><p>Traditionally, autoscaling on Kubernetes requires a massive operational stack: Prometheus to scrape metrics, Prometheus Adapter to translate them, and Horizontal Pod Autoscalers (HPAs) to act on them.</p><p>The new Hive Operator throws all of that out the window. It features a <strong>native, operator-driven control loop</strong>. When you enable autoscaling, the operator automatically injects a JMX Exporter agent into your Hive pods. The operator itself scrapes these pods and scales the StatefulSets and Deployments dynamically.</p><h3>The Autoscaling Parameters Explained</h3><p>Every component (HiveServer2, Metastore, LLAP, TezAM) accepts an autoscaling block that lets you fine-tune the operator&#39;s responsiveness:</p><ul><li><strong>enabled</strong>: Activates autoscaling for the component.</li><li><strong>minReplicas</strong>: The absolute floor for scaling. Set to 0 for LLAP and TezAM to enable scale-to-zero capabilities. HS2 and HMS enforce a minimum of 1 to ensure the cluster remains reachable.</li><li><strong>scaleUpThreshold</strong>: The metric target per pod that triggers scale-up. For HS2, this is the number of open sessions per pod. For HMS, it is the API request rate. For LLAP, it is the number of busy task slots. (TezAM scales purely on session demand, so it ignores this).</li><li><strong>metricsScrapeIntervalSeconds</strong>: How frequently the operator&#39;s internal control loop polls the JMX endpoint on your active pods. Lower values (e.g., 10s) provide faster response times.</li><li><strong>scaleUpStabilizationSeconds</strong>: A smoothing buffer to prevent flapping. The operator looks at the highest replica recommendation over this time window before committing to a scale-up.</li><li><strong>scaleDownStabilizationSeconds</strong>: The cooldown period. Traffic must remain consistently low for this duration before the operator safely removes pods.</li><li><strong>gracePeriodSeconds</strong>: The maximum safety cap for the graceful preStop drain. The operator gracefully waits for sessions/queries to finish before killing the pod. If active sessions drop to 0 before this timer expires, the pod terminates immediately.</li></ul><h3>Dual-Signal Scaling (Metrics + CPU)</h3><p>What if only a few Data Engineer submits a monstrous ETL join? The session count is low, but the CPU is pinned at 100%.</p><p>To solve this, the operator uses <strong>Dual-Signal Scaling</strong> for HS2 and HMS. It calculates desired replicas based on session/API metrics <em>and</em> CPU utilization, taking the max() of both signals.</p><ul><li><strong>cpuScaleUpThreshold</strong>: The CPU percentage (0-100) that triggers scale-up.</li><li><strong>cpuScaleDownThreshold</strong>: The CPU percentage below which scale-down is considered.</li></ul><blockquote><strong><em>Crucial Tip:</em></strong><em> Always set </em><em>resources.limitsCpu in your Kubernetes spec when using CPU-based autoscaling! The JMX metric (</em><em>ProcessCpuLoad) calculates CPU usage as a fraction of </em>available processors<em>. Without CPU limits, the JVM looks at the underlying physical Kubernetes Node. If your pod is on a 16-core node and maxes out 1 core, JMX will report 6.25% CPU usage, meaning your autoscaler may never trigger.</em></blockquote><p><strong>Example YAML Configuration for Autoscaling:</strong></p><pre>cluster:<br>  hiveServer2:<br>    replicas: 10 # Acts as the MAXIMUM ceiling when autoscaling is on<br>    resources:<br>      limitsCpu: &quot;2&quot;<br>    autoscaling:<br>      enabled: true<br>      minReplicas: 1<br>      scaleUpThreshold: 80<br>      metricsScrapeIntervalSeconds: 10<br>      scaleUpStabilizationSeconds: 60<br>      scaleDownStabilizationSeconds: 600<br>      cpuScaleUpThreshold: 90<br>      cpuScaleDownThreshold: 30</pre><h3>4. Auto-Suspend: Full Cluster Hibernation</h3><p>Autoscaling LLAP to 0 is great, but HiveServer2 and the Metastore still run 24/7. For development, testing, or intermittent analytics environments, the operator introduces <strong>Auto-Suspend</strong>.</p><p>When enabled, the operator monitors the cluster. If all components are sitting at their minReplicas and HiveServer2 registers <strong>0 open sessions</strong> for a configured duration, the operator <strong>force-scales the entire cluster (including HS2 and HMS) to 0.</strong></p><h4>Auto-Suspend Parameters</h4><ul><li><strong>enabled</strong>: Activates the hibernation routine.</li><li><strong>idleTimeoutMinutes</strong>: Minutes of 0 active sessions before the cluster auto-suspends.</li><li><strong>includeMetastore</strong>: If true, the HMS also scales to 0. If false, HMS stays alive at minReplicas to serve external metadata requests.</li></ul><h3>Observing the Hibernation Lifecycle</h3><p>You can watch the operator transition through the suspension lifecycle in real time using the kubectl get command:</p><pre># 1. Active cluster processing queries<br>$ kubectl get hivecluster hive<br>NAME   PHASE     IDLE (MIN)<br>hive   Running   <br><br># 2. Queries have finished, and the cluster begins waiting for new work<br>$ kubectl get hivecluster hive <br>NAME   PHASE     IDLE (MIN)<br>hive   Idle      10<br><br># 3. The idle timeout is reached; the cluster hibernates to save resources<br>$ kubectl get hivecluster hive <br>NAME   PHASE       IDLE (MIN) <br>hive   Suspended</pre><p>To wake the cluster up manually, simply patch the CRD:</p><pre># Wake the cluster back up<br>kubectl patch hivecluster hive --type=merge -p &#39;{&quot;spec&quot;:{&quot;suspend&quot;:false}}&#39;<br># Force hibernation immediately (bypassing the idle timer)<br>kubectl patch hivecluster hive --type=merge -p &#39;{&quot;spec&quot;:{&quot;suspend&quot;:true}}&#39;</pre><h3>5. Multi-Tenant LLAP: Beating the “Noisy Neighbor”</h3><figure><img alt="Single Tenant vs Multi Tenant" src="https://cdn-images-1.medium.com/max/1024/1*yC4zU0gw-WtCUrWQx_yBlw.png" /><figcaption>Single Tenant Vs Multi Tenant LLAP &amp; Tez AM</figcaption></figure><p>In a traditional big data environment, sharing a single compute pool causes the dreaded “Noisy Neighbor” problem. If Alice runs a massive ETL pipeline, she consumes all the LLAP executors. When Bob (a BI Analyst) opens his executive dashboard, his sub-second ad-hoc queries queue behind Alice’s massive joins.</p><p><strong>Multi-Tenant LLAP</strong> solves this by allowing you to define multiple, completely independent LLAP clusters within a <em>single</em> Hive deployment. Each cluster gets its own StatefulSet, autoscaling rules, and dedicated Tez Application Masters.</p><p>This is how the magnified flow chart looks looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpQq2gxZPrhwxbl4ohQuMQ.png" /><figcaption>Multi tenant Architecture</figcaption></figure><h3>Server-Side Routing</h3><p>The operator uses <strong>Server-Side Routing</strong> via the llapClusterRouting property. Clients require zero configuration—Hive routes them automatically based on their username or group.</p><p>Format: user:&lt;name&gt;=&lt;cluster&gt;,group:&lt;name&gt;=&lt;cluster&gt;,default=&lt;cluster&gt;</p><h3>Multi-Tenant YAML Example</h3><p>Here is how you isolate Alice from Bob:</p><pre>cluster:<br>  # Map users/groups to specific compute pools<br>  llapClusterRouting: &quot;user:alice=etl,group:analysts=bi,default=dev&quot;<br>  <br>  llapClusters:<br>    # Pool 1: ETL (Alice) - Large memory, highly scalable<br>    - name: etl<br>      replicas: 6<br>      executors: 4<br>      memoryMb: 8192<br>      autoscaling:<br>        enabled: true<br>        minReplicas: 2<br>      tezAm:<br>        autoscaling:<br>          enabled: true<br>          minReplicas: 2<br>    <br>    # Pool 2: BI (Analysts) - Smaller tasks, scales to zero aggressively<br>    - name: bi<br>      replicas: 4<br>      executors: 2<br>      memoryMb: 4096<br>      autoscaling:<br>        enabled: true<br>        minReplicas: 0<br>      tezAm:<br>        autoscaling:<br>          enabled: true<br>          minReplicas: 0</pre><p>When Bob connects via Beeline (-n bob), HiveServer2 intercepts the connection, evaluates the routing rules, and seamlessly points his session to the isolated bi compute pool. His queries trigger scale-up events for <em>that specific LLAP cluster</em>, completely unaffected by Alice&#39;s ETL workload!</p><h3>6. Connecting via Beeline &amp; Running Apache Iceberg</h3><p>With the new operator, HiveServer2 runs in <strong>HTTP transport mode</strong> by default. Because routing is handled server-side, the client requires no complex JDBC strings.</p><p>Because the operator deploys the latest Apache Hive, you get powerful modern table formats right out of the box. You can create standard native Hive tables, or seamlessly dive into <strong>Apache Iceberg</strong>.</p><p>Let’s port-forward to test the connection:</p><pre># Terminal 1: Forward the HTTP port<br>kubectl port-forward svc/hive-hiveserver2 10001:10001</pre><pre># Terminal 2: Connect using Beeline<br>beeline -u &quot;jdbc:hive2://localhost:10001/;transportMode=http;httpPath=cliservice&quot; -n alice</pre><h3>The Iceberg Experience</h3><p>Once connected, you can immediately start creating and querying Iceberg tables, as well as inspecting Iceberg’s powerful hidden metadata tables:</p><pre>0: jdbc:hive2://hive-hiveserver2:10001/&gt; create table emp (id int) stored by iceberg;<br>0: jdbc:hive2://hive-hiveserver2:10001/&gt; insert into emp values (1),(2),(3),(4);<br>0: jdbc:hive2://hive-hiveserver2:10001/&gt; select * from emp;<br>+---------+<br>| emp.id  |<br>+---------+<br>| 1       |<br>| 2       |<br>| 3       |<br>| 4       |<br>+---------+<br>4 rows selected (1.125 seconds)<br>0: jdbc:hive2://hive-hiveserver2:10001/&gt; select * from default.emp.files;<br>+--------------------+----------------------------------------------------+------------------------+--------------------+<br>| emp.files.content  |                 emp.files.file_path                | emp.files.file_format  | emp.files.spec_id  | <br>+--------------------+----------------------------------------------------+------------------------+--------------------+<br>| 0                  | s3g://ayush-ozone-bucket/hive/warehouse/emp/data/...  | PARQUET                | 0                  | <br>+--------------------+----------------------------------------------------+------------------------+--------------------+<br>1 row selected (2.675 seconds)</pre><h3>7. Observability: Real-World Operator Status</h3><p>The operator provides extensive visibility into the state of your cluster. To see exactly what the autoscaler is doing under the hood, describe the output as YAML:</p><pre>$ kubectl get hivecluster hive -o yaml</pre><p>You will see rich status blocks tracking precise autoscaling metrics for <em>each</em> individual component and tenant. Notice how it tracks the currentMetricValue, currentCpuPercent, and exactly what the autoscaler&#39;s proposedReplicas are:</p><pre>status:<br>  clusterPhase: Running<br>  conditions:<br>  - lastTransitionTime: &quot;2026-06-22T08:00:31.996154087Z&quot;<br>    message: All Hive components are ready<br>    reason: AllComponentsReady<br>    status: &quot;True&quot;<br>    type: Ready<br>  hiveServer2:<br>    currentReplicas: 2<br>    maxReplicas: 2<br>    minReplicas: 2<br>    phase: Running<br>    readyReplicas: 2<br>  llapClusters:<br>    llap0:<br>      autoscaling:<br>        currentMetricValue: 0<br>        lastScaleTime: &quot;2026-06-22T08:16:34.000537797Z&quot;<br>        proposedReplicas: 0<br>        scaleUpThreshold: 1<br>      currentReplicas: 0<br>      maxReplicas: 2<br>      minReplicas: 0<br>      phase: Idle<br>      readyReplicas: 0<br>  metastore:<br>    autoscaling:<br>      cpuProposedReplicas: 1<br>      cpuScaleUpThreshold: 90<br>      currentCpuPercent: 0.2079002079002079<br>      currentMetricValue: 0<br>      lastScaleTime: &quot;2026-06-22T08:09:37.666901757Z&quot;<br>      proposedReplicas: 1<br>      scaleUpThreshold: 5<br>    currentReplicas: 1<br>    maxReplicas: 2<br>    minReplicas: 1<br>    phase: Running<br>    readyReplicas: 1<br>  observedGeneration: 1</pre><h3>8. The Configuration Reference (The Ultimate CRD YAML)</h3><p>Instead of a fragmented list of API properties, the following represents a comprehensive HiveCluster Custom Resource YAML via a values file.</p><p>This single file replaces dozens of Deployments, ConfigMaps, and Services. It provides a blueprint for overriding Hadoop configurations (core-site.xml), injecting Hive and Tez parameters, defining database connections, and establishing multi-tenant autoscaling.</p><pre># full-stack-values.yaml<br>cluster:<br>  image: &quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot;<br>  <br>  # ---------------------------------------------------------------------------<br>  # 1. DATABASE &amp; METASTORE CONFIG<br>  # ---------------------------------------------------------------------------<br>  database:<br>    type: postgres<br>    url: &quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot;<br>    driver: &quot;org.postgresql.Driver&quot;<br>    username: hive<br>    passwordSecretRef:<br>      name: hive-db-secret<br>      key: password<br>    driverJarUrl: &quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot;<br>metastore:<br>    enabled: true<br>    replicas: 2<br>    autoscaling:<br>      enabled: true<br>      minReplicas: 1<br>      scaleUpThreshold: 5                 # API calls per second per pod<br>      cpuScaleUpThreshold: 90             # Scale up if CPU hits 90%<br>      cpuScaleDownThreshold: 30<br>  # ---------------------------------------------------------------------------<br>  # 2. ZOOKEEPER &amp; STORAGE OVERRIDES<br>  # ---------------------------------------------------------------------------<br>  zookeeper:<br>    quorum: &quot;zookeeper:2181&quot;<br>  storage:<br>    coreSiteOverrides:<br>      fs.defaultFS: &quot;s3a://hive&quot;<br>      fs.s3a.endpoint: &quot;http://ozone-s3g-rest:9878&quot;<br>      fs.s3a.path.style.access: &quot;true&quot;<br>    envVars:<br>      - name: HADOOP_OPTIONAL_TOOLS<br>        value: &quot;hadoop-aws&quot;<br>      - name: AWS_ACCESS_KEY_ID<br>        value: &quot;ozone&quot;<br>      - name: AWS_SECRET_ACCESS_KEY<br>        value: &quot;ozone&quot;<br>  # ---------------------------------------------------------------------------<br>  # 3. HIVESERVER2 &amp; HIBERNATION<br>  # ---------------------------------------------------------------------------<br>  autoSuspend:<br>    enabled: true<br>    idleTimeoutMinutes: 15    <br>    includeMetastore: true <br>  hiveServer2:<br>    replicas: 2<br>    configOverrides:<br>      hive.server2.enable.doAs: &quot;false&quot;<br>    resources:<br>      limitsCpu: &quot;2&quot;          # CRITICAL for accurate CPU autoscaling!<br>    autoscaling:<br>      enabled: true<br>      minReplicas: 1<br>      scaleUpThreshold: 80    # Active sessions per pod<br>  # ---------------------------------------------------------------------------<br>  # 4. MULTI-TENANT LLAP &amp; TEZ<br>  # ---------------------------------------------------------------------------<br>  llapClusterRouting: &quot;user:alice=llap0,user:bob=llap1,default=llap2&quot;<br>  <br>  llapClusters:<br>    - name: llap0<br>      enabled: true<br>      replicas: 2<br>      executors: 1<br>      memoryMb: 1024<br>      configOverrides:<br>        hive.llap.daemon.task.scheduler.wait.queue.size: &quot;1&quot;<br>      autoscaling:<br>        enabled: true<br>        minReplicas: 0       # Scale to zero when idle<br>        scaleUpThreshold: 1<br>      tezAm:<br>        replicas: 2<br>        autoscaling:<br>          enabled: true<br>          minReplicas: 0<br>    <br>    - name: llap1<br>      enabled: true<br>      replicas: 2<br>      executors: 1<br>      autoscaling:<br>        enabled: true<br>        minReplicas: 0<br>        scaleUpThreshold: 1<br>      tezAm:<br>        replicas: 2<br>        autoscaling:<br>          enabled: true<br>          minReplicas: 0<br>          <br>    - name: llap2<br>      enabled: true<br>      replicas: 2<br>      executors: 1<br>      autoscaling:<br>        enabled: true<br>        minReplicas: 0<br>        scaleUpThreshold: 1<br>      tezAm:<br>        replicas: 2<br>        autoscaling:<br>          enabled: true<br>          minReplicas: 0</pre><p>Deploying this is as simple as:</p><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  -f full-stack-values.yaml</pre><h3>9. The Quick-Start Helm Commands</h3><p><em>Disclaimer: The following commands utilize a custom OCI registry image (</em><em>ayushtkn/hive) containing a patched operator for testing purposes. For production deployments, ensure you are using the official Apache Hive Docker images once released.</em></p><p>If you prefer deploying without a values.yaml file, you can pass all configurations via the Helm CLI using the multi-stage quick-start below.</p><h3>Step 1: Install Core Cluster Dependencies</h3><p>Every Hive deployment requires a central coordination service and a metadata catalog database. Run these commands to spin up ZooKeeper and PostgreSQL.</p><pre># 1. Install ZooKeeper for service discovery and session management<br>helm repo add bitnami https://charts.bitnami.com/bitnami<br>helm install zookeeper bitnami/zookeeper \<br>  --set replicaCount=1 --set auth.enabled=false \<br>  --set image.repository=bitnamilegacy/zookeeper \<br>  --set image.tag=3.9.3-debian-12-r21 \<br>  --set global.security.allowInsecureImages=true --wait<br><br># 2. Install PostgreSQL to serve as the Hive Metastore database<br>helm install postgres bitnami/postgresql \<br>  --set auth.username=hive --set auth.password=hive123 \<br>  --set auth.database=metastore --wait<br><br># 3. Securely store the database credentials in a Kubernetes Secret<br>kubectl create secret generic hive-db-secret --from-literal=password=hive123</pre><h3>Step 2: Install Storage (Apache Ozone)</h3><p>If you are testing locally and do not have an existing cloud object store (like Apache Ozone, AWS S3 or GCS), execute the following commands to provision Apache Ozone as your local S3-compatible file system. <strong>Skip this step entirely if you plan to target existing or native cloud storage buckets.</strong></p><pre># 1. Install the local Apache Ozone cluster<br>helm repo add ozone https://apache.github.io/ozone-helm-charts/<br>helm install ozone ozone/ozone --version 0.2.0 --wait<br>sleep 50<br><br># 2. Provision the storage volume and target data bucket inside Ozone<br>kubectl exec statefulset/ozone-om -- ozone sh volume create /s3v<br>kubectl exec statefulset/ozone-om -- ozone sh bucket create /s3v/hive</pre><h3>Step 3: Deploy the Hive Operator (Choose Your Scenario)</h3><p><em>(Notice how backslashes </em><em>\ are used to escape dots in </em><em>coreSiteOverrides, preventing Helm from interpreting them as nested YAML objects).</em></p><h4>Scenario A: Auto-Scaling Disabled (Apache Ozone)</h4><p>Sets up a static, single-tenant Hive cluster pointing to our local Apache Ozone bucket and Postgres database.</p><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  --set operator.image.repository=&quot;ayushtkn/hive&quot; \<br>  --set operator.image.tag=&quot;operator-4.3.0-SNAPSHOT&quot; \<br>  --set cluster.image=&quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot; \<br>  --set cluster.database.type=postgres \<br>  --set cluster.database.url=&quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot; \<br>  --set cluster.database.driver=&quot;org.postgresql.Driver&quot; \<br>  --set cluster.database.username=hive \<br>  --set cluster.database.passwordSecretRef.name=hive-db-secret \<br>  --set cluster.database.passwordSecretRef.key=password \<br>  --set cluster.database.driverJarUrl=&quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot; \<br>  --set cluster.zookeeper.quorum=&quot;zookeeper:2181&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.defaultFS&quot;=&quot;s3a://hive&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.endpoint&quot;=&quot;http://ozone-s3g-rest:9878&quot; \<br>  --set-string cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.path\.style\.access&quot;=true \<br>  --set &#39;cluster.storage.envVars[0].name=HADOOP_OPTIONAL_TOOLS&#39; \<br>  --set &#39;cluster.storage.envVars[0].value=hadoop-aws&#39; \<br>  --set &#39;cluster.storage.envVars[1].name=AWS_ACCESS_KEY_ID&#39; \<br>  --set &#39;cluster.storage.envVars[1].value=ozone&#39; \<br>  --set &#39;cluster.storage.envVars[2].name=AWS_SECRET_ACCESS_KEY&#39; \<br>  --set &#39;cluster.storage.envVars[2].value=ozone&#39;</pre><h4>Scenario B: Auto-Scaling Enabled, Single Tenant (Apache Ozone)</h4><p>Activates intelligent autoscaling for HiveServer2, Metastore, LLAP, and TezAM, while turning on the Auto-Suspend hibernation feature.</p><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  --set operator.image.repository=&quot;ayushtkn/hive&quot; \<br>  --set operator.image.tag=&quot;operator-4.3.0-SNAPSHOT&quot; \<br>  --set cluster.image=&quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot; \<br>  --set cluster.database.type=postgres \<br>  --set cluster.database.url=&quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot; \<br>  --set cluster.database.driver=&quot;org.postgresql.Driver&quot; \<br>  --set cluster.database.username=hive \<br>  --set cluster.database.passwordSecretRef.name=hive-db-secret \<br>  --set cluster.database.passwordSecretRef.key=password \<br>  --set cluster.database.driverJarUrl=&quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot; \<br>  --set cluster.zookeeper.quorum=&quot;zookeeper:2181&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.defaultFS&quot;=&quot;s3a://hive&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.endpoint&quot;=&quot;http://ozone-s3g-rest:9878&quot; \<br>  --set-string cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.path\.style\.access&quot;=true \<br>  --set &#39;cluster.storage.envVars[0].name=HADOOP_OPTIONAL_TOOLS&#39; \<br>  --set &#39;cluster.storage.envVars[0].value=hadoop-aws&#39; \<br>  --set &#39;cluster.storage.envVars[1].name=AWS_ACCESS_KEY_ID&#39; \<br>  --set &#39;cluster.storage.envVars[1].value=ozone&#39; \<br>  --set &#39;cluster.storage.envVars[2].name=AWS_SECRET_ACCESS_KEY&#39; \<br>  --set &#39;cluster.storage.envVars[2].value=ozone&#39; \<br>  --set cluster.hiveServer2.autoscaling.enabled=true \<br>  --set cluster.metastore.autoscaling.enabled=true \<br>  --set cluster.autoSuspend.enabled=true \<br>  --set &#39;cluster.llapClusters[0].name=llap0&#39; \<br>  --set &#39;cluster.llapClusters[0].autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[0].tezAm.autoscaling.enabled=true&#39;</pre><h4>Scenario C: Multi-Tenant Autoscaling (Apache Ozone)</h4><p>Our ultimate architecture. Injects server-side routing rules and provisions three fully independent LLAP and TezAM clusters, configured to auto-scale independently.</p><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  --set operator.image.repository=&quot;ayushtkn/hive&quot; \<br>  --set operator.image.tag=&quot;operator-4.3.0-SNAPSHOT&quot; \<br>  --set cluster.image=&quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot; \<br>  --set cluster.database.type=postgres \<br>  --set cluster.database.url=&quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot; \<br>  --set cluster.database.driver=&quot;org.postgresql.Driver&quot; \<br>  --set cluster.database.username=hive \<br>  --set cluster.database.passwordSecretRef.name=hive-db-secret \<br>  --set cluster.database.passwordSecretRef.key=password \<br>  --set cluster.database.driverJarUrl=&quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot; \<br>  --set cluster.zookeeper.quorum=&quot;zookeeper:2181&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.defaultFS&quot;=&quot;s3a://hive&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.endpoint&quot;=&quot;http://ozone-s3g-rest:9878&quot; \<br>  --set-string cluster.storage.coreSiteOverrides.&quot;fs\.s3a\.path\.style\.access&quot;=true \<br>  --set &#39;cluster.storage.envVars[0].name=HADOOP_OPTIONAL_TOOLS&#39; \<br>  --set &#39;cluster.storage.envVars[0].value=hadoop-aws&#39; \<br>  --set &#39;cluster.storage.envVars[1].name=AWS_ACCESS_KEY_ID&#39; \<br>  --set &#39;cluster.storage.envVars[1].value=ozone&#39; \<br>  --set &#39;cluster.storage.envVars[2].name=AWS_SECRET_ACCESS_KEY&#39; \<br>  --set &#39;cluster.storage.envVars[2].value=ozone&#39; \<br>  --set cluster.hiveServer2.autoscaling.enabled=true \<br>  --set cluster.metastore.autoscaling.enabled=true \<br>  --set cluster.autoSuspend.enabled=true \<br>  --set-string &#39;cluster.llapClusterRouting=user:alice=llap0\,user:bob=llap1\,default=llap2&#39; \<br>  --set &#39;cluster.llapClusters[0].name=llap0&#39; \<br>  --set &#39;cluster.llapClusters[0].autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[0].tezAm.autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[1].name=llap1&#39; \<br>  --set &#39;cluster.llapClusters[1].autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[1].tezAm.autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[2].name=llap2&#39; \<br>  --set &#39;cluster.llapClusters[2].autoscaling.enabled=true&#39; \<br>  --set &#39;cluster.llapClusters[2].tezAm.autoscaling.enabled=true&#39;</pre><h4>Scenario D: AWS S3 (Single Tenant)</h4><p>Connects directly to native AWS S3. Here, we create a Kubernetes Secret for our AWS credentials and securely map them to the operator using valueFrom.secretKeyRef.</p><pre># First, create your AWS credentials secret<br>kubectl create secret generic aws-s3-creds \<br>  --from-literal=accessKey=&quot;&lt;YOUR_ACCESS_KEY&gt;&quot; \<br>  --from-literal=secretKey=&quot;&lt;YOUR_SECRET_KEY&gt;&quot;</pre><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  --set operator.image.repository=&quot;ayushtkn/hive&quot; \<br>  --set operator.image.tag=&quot;operator-4.3.0-SNAPSHOT&quot; \<br>  --set cluster.image=&quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot; \<br>  --set cluster.database.type=postgres \<br>  --set cluster.database.url=&quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot; \<br>  --set cluster.database.driver=&quot;org.postgresql.Driver&quot; \<br>  --set cluster.database.username=hive \<br>  --set cluster.database.passwordSecretRef.name=hive-db-secret \<br>  --set cluster.database.passwordSecretRef.key=password \<br>  --set cluster.database.driverJarUrl=&quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot; \<br>  --set cluster.zookeeper.quorum=&quot;zookeeper:2181&quot; \<br>  --set cluster.storage.coreSiteOverrides.&quot;fs\.defaultFS&quot;=&quot;s3a://ayush-k8s-bucket&quot; \<br>  --set &#39;cluster.storage.envVars[0].name=HADOOP_OPTIONAL_TOOLS&#39; \<br>  --set &#39;cluster.storage.envVars[0].value=hadoop-aws&#39; \<br>  --set &#39;cluster.storage.envVars[1].name=AWS_ACCESS_KEY_ID&#39; \<br>  --set &#39;cluster.storage.envVars[1].valueFrom.secretKeyRef.name=aws-s3-creds&#39; \<br>  --set &#39;cluster.storage.envVars[1].valueFrom.secretKeyRef.key=accessKey&#39; \<br>  --set &#39;cluster.storage.envVars[2].name=AWS_SECRET_ACCESS_KEY&#39; \<br>  --set &#39;cluster.storage.envVars[2].valueFrom.secretKeyRef.name=aws-s3-creds&#39; \<br>  --set &#39;cluster.storage.envVars[2].valueFrom.secretKeyRef.key=secretKey&#39;</pre><h4>Scenario E: Google Cloud Storage (GCS)</h4><p>Connects directly to GCP storage. We map a JSON service account keyfile as a Secret, instruct the operator to mount it as a volume, and inject the GCS connector JAR.</p><pre># First, create your GCS secret from a JSON keyfile<br>kubectl create secret generic gcs-creds  --from-file=key.json=/path/to/key.json</pre><pre>helm install hive oci://registry-1.docker.io/ayushtkn/hive-operator \<br>  --version 4.3.0-SNAPSHOT \<br>  --set operator.image.repository=&quot;ayushtkn/hive&quot; \<br>  --set operator.image.tag=&quot;operator-4.3.0-SNAPSHOT&quot; \<br>  --set cluster.image=&quot;ayushtkn/hive:4.3.0-SNAPSHOT&quot; \<br>  --set cluster.database.type=postgres \<br>  --set cluster.database.url=&quot;jdbc:postgresql://postgres-postgresql:5432/metastore&quot; \<br>  --set cluster.database.driver=&quot;org.postgresql.Driver&quot; \<br>  --set cluster.database.username=hive \<br>  --set cluster.database.passwordSecretRef.name=hive-db-secret \<br>  --set cluster.database.passwordSecretRef.key=password \<br>  --set cluster.database.driverJarUrl=&quot;https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.5/postgresql-42.7.5.jar&quot; \<br>  --set cluster.zookeeper.quorum=&quot;zookeeper:2181&quot; \<br>  --set &#39;cluster.storage.coreSiteOverrides.fs\.defaultFS=gs://ayush-gcs-bucket&#39; \<br>  --set &#39;cluster.storage.coreSiteOverrides.fs\.gs\.impl=com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem&#39; \<br>  --set &#39;cluster.storage.coreSiteOverrides.fs\.gs\.auth\.type=SERVICE_ACCOUNT_JSON_KEYFILE&#39; \<br>  --set &#39;cluster.storage.coreSiteOverrides.fs\.gs\.auth\.service\.account\.json\.keyfile=/etc/gcs/key.json&#39; \<br>  --set-string &#39;cluster.storage.coreSiteOverrides.fs\.gs\.reported\.permissions=777&#39; \<br>  --set &#39;cluster.storage.externalJars[0]=https://repo1.maven.org/maven2/com/google/cloud/bigdataoss/gcs-connector/hadoop3-2.2.25/gcs-connector-hadoop3-2.2.25-shaded.jar&#39; \<br>  --set &#39;cluster.storage.volumes[0].name=gcs-key&#39; \<br>  --set &#39;cluster.storage.volumes[0].secret.secretName=gcs-creds&#39; \<br>  --set &#39;cluster.storage.volumeMounts[0].name=gcs-key&#39; \<br>  --set &#39;cluster.storage.volumeMounts[0].mountPath=/etc/gcs&#39; \<br>  --set &#39;cluster.storage.volumeMounts[0].readOnly=true&#39;</pre><p>The AWS S3 &amp; GCS examples are for Single Tenant architecture but they support AutoScaling &amp; Multi Tenancy similar to the Ozone examples and can be configured accordingly</p><h3>10. The Road Ahead: Tech Preview &amp; Future Work</h3><p>The Kubernetes operator is officially arriving as part of the upcoming <strong>Apache Hive 4.3 release</strong> and <strong>Apache Tez 1.0.0</strong> as an exciting <strong>Tech Preview</strong>.</p><p>This foundational release shifts Hive from a core on-premises architecture to a deeply integrated, highly dynamic elastic resource provider. But the community isn’t stopping there. Here is a sneak peek at the features slated for upcoming versions of the operator:</p><ul><li><strong>Persistable Sessions in Apache Hive:</strong> Session recovery will soon allow execution context to persist across transient networking disconnects or container restarts, insulating long-running analytical jobs from platform-level failures.</li><li><strong>AI-Enabled UI for the Hive Operator:</strong> An intelligent dashboard is in development to provide visual tracing for data pool routing, real-world metrics parsing, and AI-driven autoscaler optimization recommendations.</li></ul><h3>A Note on the Testing Artifacts</h3><p><em>The Helm charts (</em><em>ayushtkn/hive-operator) and container images used in the quickstart examples are part of a personal testing registry compiled directly from the latest master branch source code. They are provided to allow early experimentation prior to the formal Apache releases and aren’t meant for production use case nor are replacement to official Apache Hive releases.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d3e4427121a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Hive-4.3x+ With Apache Iceberg V3]]></title>
            <link>https://medium.com/@ayushtkn/apache-hive-4-3x-with-apache-iceberg-v3-d33483ab0977?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d33483ab0977</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[apache-iceberg]]></category>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[apache-hadoop]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Thu, 30 Apr 2026 14:49:04 GMT</pubDate>
            <atom:updated>2026-07-28T17:27:44.933Z</atom:updated>
            <content:encoded><![CDATA[<p><em>by </em><a href="https://www.linkedin.com/in/ayush151/"><em>Ayush Saxena</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9pYai5vqwM-xXw-Bh9aeQ.png" /><figcaption>Apache Hive 4.3.x with Apache Iceberg V3</figcaption></figure><p>The data lakehouse ecosystem is evolving rapidly, and Apache Iceberg continues to lead the charge. With the introduction of the V3 specification, Iceberg brings significant improvements in storage efficiency, advanced data types, and precise row-level tracking.</p><p>In this post, we will dive deep into what Iceberg V3 brings to the table in the upcoming Apache Hive 4.3.x release, how to manage V3 tables in Hive, and explore the new features with hands-on examples — giving you a comprehensive look under the hood so you are ready the moment the release drops.</p><h3>Getting Started: Creating and Upgrading to V3</h3><p>Working with Iceberg V3 in Hive is straightforward. You simply need to specify the format-versionas <strong>3</strong> in your table properties.</p><h4>Creating a New Iceberg V3 Table</h4><p>To create a fresh table adhering to the V3 specification, use the format-version table property:</p><pre>CREATE TABLE ice01 (<br>    id INT<br>) <br>STORED BY ICEBERG<br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;);</pre><h3>Upgrading an Existing V1/V2 Table to V3</h3><p>If you have existing Iceberg V1 or V2 tables, upgrading them to V3 is a metadata-only operation.</p><pre>ALTER TABLE ice01 SET TBLPROPERTIES(&#39;format-version&#39;=&#39;3&#39;);</pre><blockquote><strong><em>Important Considerations Before Upgrading:</em></strong></blockquote><ul><li><strong>One-Way Street:</strong> Once a table is converted to V3, it <strong>cannot be downgraded</strong> back to V2 or V1.</li><li><strong>No Instant Rewrite:</strong> Converting to V3 doesn’t trigger a massive data rewrite. Existing data files remain exactly as they are.</li><li><strong>New Data Follows V3:</strong> Only new data ingested or updated after the conversion will follow the V3 specifications.</li></ul><h3>What’s New in Iceberg V3?</h3><p>The V3 spec isn’t just a minor update; it introduces powerful architectural changes and new data capabilities. Let’s break them down.</p><h3>1. Deletion Vectors (DVs)</h3><p>In Iceberg V2, Row-Level deletes were handled using Position Delete files. While effective, this could lead to a proliferation of small delete files that degraded read performance.</p><p>V3 introduces <strong>Deletion Vectors</strong>.</p><ul><li><strong>How it works:</strong> Deletion vectors identify deleted rows within a file by encoding the deleted positions into a highly compressed bitmap. If the bit at position <em>P</em> is set, it indicates that the row at position <em>P</em> is deleted.</li><li><strong>The Advantage:</strong> Once a table is on V3, you get one DV per DataFile. For existing DataFiles that previously relied on Position Delete files, any subsequent operations (like an update or delete) will write a new Deletion Vector, making the old Position Delete files obsolete. This drastically speeds up read times by allowing engines to filter out deleted rows efficiently in memory.</li></ul><h3>2. Row Lineage Tracking</h3><p>One of the most fundamental structural additions in Iceberg V3 is native row lineage tracking. If you are building Change Data Capture (CDC) pipelines or auditing data lakes, this solves the long-standing challenge of tracking the physical lifecycle of individual rows deterministically.</p><p>The core of this system, baked directly into the engine, relies on two automatically managed hidden columns:</p><ul><li><strong>ROW__LINEAGE__ID</strong>: A stable, sequentially assigned integer (e.g., 0, 1, 2...) given to a row at the exact moment of its initial insertion. This ID acts as the permanent anchor for the row&#39;s identity and is preserved across logical mutations.</li><li><strong>LAST__UPDATED__SEQUENCE__NUMBER</strong>: Tracks the snapshot or transaction sequence number that last mutated this specific row.</li></ul><h4>How the Mechanics Work</h4><p>When you perform an UPDATE on a V3 table, the system doesn&#39;t just execute a disconnected physical delete and insert. The core lineage logic ensures that the new version of the row inherits the exact same ROW__LINEAGE__ID as the old version, while the LAST__UPDATED__SEQUENCE__NUMBER is bumped to the current transaction&#39;s sequence number.</p><p>This creates an unbreakable link between the past and present states of a logical row.</p><h4>Real-World Example: Tracking State Mutations</h4><p>Let’s look at exactly how this behaves using standard SQL operations on an Iceberg V3 table.</p><p><strong>Step 1: Initial Ingestion</strong> First, we create our table and insert a batch of four records.</p><pre>CREATE TABLE ice_t (<br>  id INT, <br>  name STRING, <br>  balance INT<br>) <br>STORED BY ICEBERG <br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;);</pre><p>Insert:</p><pre>INSERT INTO ice_t VALUES <br>  (1, &#39;aaa&#39;, 25),<br>  (2, &#39;bbb&#39;, 35),<br>  (3, &#39;ccc&#39;, 82),<br>  (4, &#39;ddd&#39;, 91);</pre><p>By querying the table and explicitly selecting the hidden lineage columns, we can see the baseline state generated by the first transaction (Sequence Number 1):</p><pre>SELECT <br>  id, name, balance, <br>  ROW__LINEAGE__ID, <br>  LAST__UPDATED__SEQUENCE__NUMBER <br>FROM ice_t <br>ORDER BY id;</pre><p><em>Output (Initial State):</em></p><pre>id | name | balance | ROW__LINEAGE__ID | LAST__UPDATED__SEQUENCE__NUMBER<br>---|------|---------|------------------|--------------------------------<br>1  | aaa  | 25      | 0                | 1<br>2  | bbb  | 35      | 1                | 1<br>3  | ccc  | 82      | 2                | 1<br>4  | ddd  | 91      | 3                | 1</pre><p>Notice how the ROW__LINEAGE__ID is sequentially assigned starting from 0.</p><p><strong>Step 2: Performing a Logical Update</strong> Now, let’s modify the balance for the user with id = 2 (which corresponds to ROW__LINEAGE__ID = 1).</p><pre>UPDATE ice_t SET balance = 500 WHERE id = 2;</pre><p>Let’s inspect the lineage columns again:</p><pre>SELECT <br>  id, name, balance, <br>  ROW__LINEAGE__ID, <br>  LAST__UPDATED__SEQUENCE__NUMBER <br>FROM ice_t <br>ORDER BY id;</pre><p><em>Output (After Update):</em></p><pre>id | name | balance | ROW__LINEAGE__ID | LAST__UPDATED__SEQUENCE__NUMBER<br>---|------|---------|------------------|--------------------------------<br>1  | aaa  | 25      | 0                | 1<br>2  | bbb  | 500     | 1                | 2<br>3  | ccc  | 82      | 2                | 1<br>4  | ddd  | 91      | 3                | 1</pre><p>Here, the core lineage system has done its job. The logical entity maintained its ROW__LINEAGE__ID of 1, tying it directly to the original insert. Meanwhile, its sequence number advanced to 2, marking the specific snapshot of the mutation.</p><h4>Handling Complex Operations: MERGE INTO</h4><p>The engine’s tracking is robust enough to handle complex MERGE operations seamlessly, applying the correct lineage logic to both MATCHED and NOT MATCHED records simultaneously.</p><p>Imagine we have a source table (src) with new data, and we merge it into an existing Iceberg table (ice_merge):</p><pre>MERGE INTO ice_merge t<br>USING src s<br>ON t.id = s.id<br>WHEN MATCHED THEN<br>  UPDATE SET data = s.data<br>WHEN NOT MATCHED THEN<br>  INSERT VALUES (s.id, s.data);</pre><p>If the merge operation updates an existing row and inserts a brand new one within the same transaction (Sequence Number 2), the system perfectly routes the lineage:</p><p><em>Output (After Merge):</em></p><pre>id | data | ROW__LINEAGE__ID | LAST__UPDATED__SEQUENCE__NUMBER <br>---|------|------------------|--------------------------------<br>1  | a    | 0                | 1                               <br>2  | bb   | 1                | 2  &lt;-- Updated: Preserved ID, New Sequence<br>3  | c    | 2                | 1                               <br>4  | d    | 4                | 2  &lt;-- Inserted: New ID, New Sequence</pre><h4>The CDC Payoff</h4><p>Because the engine provides this mathematically deterministic tracking, downstream CDC pipelines become trivial to write. If a downstream dashboard only needs to pull data modified during or after sequence 2, it simply queries against the sequence number:</p><pre>SELECT <br>  id, name, balance, ROW__LINEAGE__ID <br>FROM ice_t <br>WHERE LAST__UPDATED__SEQUENCE__NUMBER &gt;= 2;</pre><p>You capture exactly what changed, with absolute certainty of the row’s historical identity.</p><h3>3. The VARIANT Data Type</h3><p>Handling semi-structured data just got much better with the VARIANT data type. It allows you to store schema-less or dynamically typed data natively.</p><p><strong>Creation and Insertion:</strong></p><pre>CREATE EXTERNAL TABLE variant_test_basic (<br>    id INT,<br>    data VARIANT<br>) STORED BY ICEBERG <br>TBLPROPERTIES(&#39;format-version&#39;=&#39;3&#39;);</pre><p>Insert:</p><pre>-- Inserting various JSON types<br>INSERT INTO variant_test_basic VALUES<br>(1, parse_json(&#39;null&#39;)),<br>(2, parse_json(&#39;true&#39;)),<br>(3, parse_json(&#39;false&#39;)),<br>(4, parse_json(&#39;42&#39;)),<br>(5, parse_json(&#39;3.14&#39;)),<br>(6, parse_json(&#39;&quot;hello world&quot;&#39;));</pre><p><strong>Retrieval:</strong></p><pre>SELECT id, to_json(data) as json_data FROM variant_test_basic ORDER BY id;</pre><p><em>Sample Output:</em></p><pre>id | json_data<br>---|----------<br>1  | null<br>2  | true<br>3  | false<br>4  | 42<br>5  | 3.14<br>6  | &quot;hello world&quot;</pre><p><strong>Variant Shredding: </strong>For complex structures and highly queried JSON fields, V3 supports “shredding” to extract variant sub-columns into their own physical columns for columnar read performance. It can be enabled via the &#39;variant.shredding.enabled&#39;=&#39;true&#39;table property.</p><pre>CREATE EXTERNAL TABLE shredded_variant_ppd (<br>  id INT,<br>  data VARIANT<br>) STORED BY ICEBERG<br>TBLPROPERTIES (<br>  &#39;format-version&#39;=&#39;3&#39;,<br>  &#39;variant.shredding.enabled&#39;=&#39;true&#39;<br>);</pre><p><em>(For a deeper dive into Variant DataType in Apache Hive-Iceberg, check out my previous blog here: </em><a href="https://medium.com/@ayushtkn/basic-variant-datatype-support-in-apache-hive-with-apache-iceberg-93c8518fcea9">https://medium.com/@ayushtkn/basic-variant-datatype-support-in-apache-hive-with-apache-iceberg-93c8518fcea9</a><em>)</em></p><h3>4. Nanosecond Timestamp Precision</h3><p>For high-frequency trading, IoT sensor telemetry, and precise distributed system logging, microsecond precision simply isn’t enough. Events can happen thousands of times within a single microsecond, and losing that granularity can disrupt time-series analytics and event ordering.</p><p>Historically, Iceberg was limited to microsecond precision. Iceberg V3 officially breaks this barrier, and Hive now natively supports reading, writing, and casting <strong>nanosecond precision timestamps</strong>.</p><p>This feature introduces a new precision indicator — (9)—which can be applied to both standard timestamps and local timezone timestamps.</p><h4>Seeing it in Action: Microsecond vs. Nanosecond</h4><p>To truly see the engine at work, let’s look at a side-by-side comparison. We will create a V3 table containing standard microsecond columns alongside their new nanosecond counterparts, and insert a highly precise timestamp: &#39;2025-12-18 10:15:30.123456789&#39;.</p><pre>-- Create a table testing both precisions and timezone variants<br>CREATE TABLE t (<br>  ts_ms          TIMESTAMP,           -- Default microsecond precision<br>  ts_ns          TIMESTAMP(9),        -- Nanosecond precision<br>  ts_local_tz_ms TIMESTAMPLOCALTZ,    -- Local timezone microsecond<br>  ts_local_tz_ns TIMESTAMPLOCALTZ(9)  -- Local timezone nanosecond<br>)<br>STORED BY ICEBERG<br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;);</pre><p>Insertion:</p><pre>-- Insert a timestamp with exactly 9 digits of fractional seconds<br>INSERT INTO t VALUES (<br>  &#39;2025-12-18 10:15:30.123456789&#39;,<br>  &#39;2025-12-18 10:15:30.123456789&#39;,<br>  &#39;2025-12-18 10:15:30.123456789&#39;,<br>  &#39;2025-12-18 10:15:30.123456789&#39;<br>);</pre><p>When we query this data back, the engine’s precision handling becomes crystal clear. The default columns silently truncate the data, while the (9) columns preserve the exact moment in time perfectly.</p><p>Query the table:</p><pre>SELECT * FROM t;</pre><p><em>Output:</em></p><pre>ts_ms          | 2025-12-18 10:15:30.123456               &lt;-- Truncated<br>ts_ns          | 2025-12-18 10:15:30.123456789            &lt;-- Preserved<br>ts_local_tz_ms | 2025-12-18 10:15:30.123456 US/Pacific    &lt;-- Truncated<br>ts_local_tz_ns | 2025-12-18 10:15:30.123456789 US/Pacific &lt;-- Preserved</pre><h4>Seamless Data Pipelining (CTAS Support)</h4><p>One of the most critical aspects of this feature is that the precision type is deeply integrated into Hive’s schema evolution and metadata tracking. This means your downstream data pipelines won’t accidentally drop precision during transformations.</p><p>For example, if you run a CREATE TABLE AS SELECT (CTAS) operation, the engine flawlessly propagates the (9)precision into the new table&#39;s schema and preserves the data entirely:</p><pre>CREATE TABLE tgt <br>STORED BY ICEBERG <br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;) <br>AS SELECT * FROM t;</pre><p>Query the tgt table:</p><pre>SELECT * FROM tgt;</pre><p><em>Output:</em></p><pre>ts_ms                      | ts_ns                         | ts_local_tz_ms                        | ts_local_tz_ns<br>---------------------------|-------------------------------|---------------------------------------|-------------------------------------------<br>2025-12-18 10:15:30.123456 | 2025-12-18 10:15:30.123456789 | 2025-12-18 10:15:30.123456 US/Pacific | 2025-12-18 10:15:30.123456789 US/Pacific</pre><p><em>(The schema perfectly maps </em><em>tgt.ts_ns to </em><em>TIMESTAMP(9) behind the scenes).</em></p><p>This robust handling ensures that once your data enters the data lakehouse with nanosecond fidelity, it stays that way across your entire analytical ecosystem.</p><h3>5. The UNKNOWN DataType</h3><p>Sometimes, downstream systems, data ingestion frameworks, or schema evolution processes require columns to exist in the metadata before their actual data types are determined. Iceberg V3 addresses this gracefully with the introduction of the UNKNOWN data type.</p><p><strong>How the Mechanics Work:</strong></p><ul><li><strong>Null Only:</strong> Columns of type UNKNOWN strictly accept only NULL values. The engine inherently maps this to a VOIDvector under the hood, meaning if you attempt to insert actual data into this column, it will throw an error.</li><li><strong>Zero Storage Footprint:</strong> Because they only represent missing or placeholder data, UNKNOWN columns are completely virtual. They are <strong>not</strong> written to or stored in the underlying Parquet data files, saving I/O and physical storage space.</li></ul><p>Let’s create a table using the new type and insert some data:</p><pre>CREATE EXTERNAL TABLE unknown_test_basic (<br>    id INT,<br>    placeholder UNKNOWN<br>) STORED BY ICEBERG <br>TBLPROPERTIES(&#39;format-version&#39;=&#39;3&#39;);<br><br>INSERT INTO unknown_test_basic VALUES<br>(1, NULL),<br>(2, NULL);</pre><p>When you query the table, the engine simply resolves the placeholder at read-time:</p><pre>SELECT id, placeholder FROM unknown_test_basic ORDER BY id;</pre><p><strong>Output:</strong></p><pre> id | placeholder <br>----|-------------<br> 1  | NULL        <br> 2  | NULL</pre><h4>Seamless Pipeline Propagation</h4><p>Just like the nanosecond precision updates, Hive handles UNKNOWN types perfectly during pipeline transformations. Whether you use CREATE TABLE LIKE (CTLT) or CREATE TABLE AS SELECT (CTAS) operations, the metadata is preserved.</p><pre>-- CTAS preserves unknown column types from the query schema<br>CREATE TABLE unknown_test_ctas <br>STORED BY ICEBERG <br>TBLPROPERTIES(&#39;format-version&#39;=&#39;3&#39;) <br>AS SELECT * FROM unknown_test_basic;</pre><h3>6. Native Table-Level Encryption</h3><p>Security in the data lakehouse is getting a major upgrade. Iceberg V3 on Hive 4.3.x introduces robust, native <strong>Table-Level Encryption</strong>. You can now secure your data completely at rest using your organization’s Key Management Service (KMS), without altering how users interact with the tables.</p><p>What makes this implementation particularly impressive is the addition of <strong>Metadata Tamperproofing</strong>. When you encrypt a table, Hive calculates a secure signature (a SHA-256 hash) of the Iceberg metadata and locks it inside the Hive Metastore (HMS). If someone tries to manually alter or swap the underlying metadata files in the storage layer to bypass access controls, Hive instantly detects the mismatch and blocks all access to the table.</p><h4>Seeing it in Action</h4><p>Setting up an encrypted table requires zero complex configuration — you just define your KMS key directly in the table properties:</p><pre>-- Create an encrypted Iceberg V3 table <br>CREATE EXTERNAL TABLE encrypted_v3_table (<br>    id BIGINT, <br>    data STRING<br>) <br>STORED BY ICEBERG <br>TBLPROPERTIES (<br>    &#39;format-version&#39;=&#39;3&#39;,<br>    &#39;encryption.table.key&#39;=&#39;my-secure-master-key&#39;,  -- The KMS Master Key ID<br>    &#39;encryption.dek.length&#39;=&#39;16&#39;                    -- Optional Data Encryption Key length<br>);</pre><p>Once the table is created, Hive handles all the heavy lifting completely behind the scenes. Your data engineers and analysts can continue running INSERT, UPDATE, DELETE, and SELECT queries exactly as they always have—enjoying enterprise-grade security with zero changes to their daily workflows or downstream dashboards.</p><h3>7. Advanced Column Defaults</h3><p>Iceberg V3 introduces sophisticated default value tracking for both primitive fields and STRUCT fields (both nested structs and the top-level schema&#39;s struct). It manages defaults using two distinct concepts:</p><ul><li><strong>initial-default</strong>: Used to populate the field&#39;s value for all records that were written <em>before</em> the field was added to the schema. This kicks in during Schema Evolution.</li><li><strong>write-default</strong>: Used to populate the field&#39;s value for any records written <em>after</em> the field was added to the schema, if the writer does not supply the field&#39;s value.</li></ul><blockquote><strong><em>Note:</em></strong><em> The </em><em>initial-default is set only when a field is added to an existing schema and </em><strong><em>cannot be changed later</em></strong><em>. Subsequent alters will only change the </em><em>write-default. If either default is not set for an optional field, the default value safely falls back to </em><em>NULL for compatibility with older spec versions.</em></blockquote><h4>Technical Mechanics</h4><p>The initial-default and write-default produce standard SQL default value behavior without requiring any existing data files to be rewritten.</p><ul><li><strong>Read-Time Evaluation (</strong><strong>initial-default):</strong> When a field is added, the engine dynamically applies the initial-default at read-time for all older rows, handling them as if they were originally written with this value.</li><li><strong>Write-Time Evaluation (</strong><strong>write-default):</strong> When a write occurs and a field is omitted, the engine physically writes the current write-default value directly into the new data file. Because this value is permanently recorded at the time of ingestion, any subsequent changes to the default value will <em>only</em> impact new writes.</li></ul><p>Let’s look at how this behaves in practice within Hive.</p><h4>Table Creation with Nested Struct Defaults</h4><p>The system fully supports complex nested structures natively. Here, we create a table with a deeply nested person struct, alongside some primitive defaults.</p><pre>CREATE TABLE t3 (<br>  id INT,<br>  category STRING DEFAULT &#39;general&#39;,<br>  score DECIMAL(5,2) DEFAULT 100.00,<br>  person STRUCT&lt;<br>    name: STRING,<br>    address: STRUCT&lt;<br>      street: STRING,<br>      city: STRING<br>    &gt;<br>  &gt; DEFAULT &#39;{&quot;name&quot;:&quot;John&quot;,&quot;address&quot;:{&quot;street&quot;:&quot;Main St&quot;,&quot;city&quot;:&quot;New York&quot;}}&#39;<br>)<br>STORED BY ICEBERG<br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;);</pre><p>If we insert a row but completely omit the person, category, and score fields, the engine enforces the write-default at ingestion:</p><pre>INSERT INTO t3 (id) VALUES (8);</pre><p>Query the table:</p><pre>SELECT id, category, score, person FROM t3 WHERE id = 8;</pre><p><em>Output:</em></p><pre>id | category | score  | person<br>---|----------|--------|----------------------------------------------------------------<br>8  | general  | 100.00 | {&quot;name&quot;:&quot;John&quot;,&quot;address&quot;:{&quot;street&quot;:&quot;Main St&quot;,&quot;city&quot;:&quot;New York&quot;}}</pre><h4>Schema Evolution: The initial-default in Action</h4><p>To see the dual-default system shine, we look at schema evolution. We will create a base table, insert a row, and then add new columns.</p><pre>-- Create base table and insert the first record<br>CREATE TABLE ice_parq (<br>  id INT<br>)<br>STORED BY ICEBERG<br>TBLPROPERTIES (&#39;format-version&#39;=&#39;3&#39;);</pre><p>Insert:</p><pre>INSERT INTO ice_parq (id) VALUES (1);</pre><p>Add new columns:</p><pre>-- Evolve the schema by adding new columns with defaults<br>ALTER TABLE ice_parq ADD COLUMNS (<br>  name STRING DEFAULT &#39;unknown&#39;,<br>  age INT DEFAULT 25,<br>  is_active BOOLEAN DEFAULT TRUE<br>);</pre><p>At execution, the metadata permanently locks in the initial-default for these three columns. When we insert a second record (triggering the write-default) and query the table, the engine dynamically resolves the missing fields for the older data file:</p><pre>INSERT INTO ice_parq (id) VALUES (2);</pre><p>Query the table:</p><pre>SELECT * FROM ice_parq ORDER BY id;</pre><p><em>Output:</em></p><pre>id | name    | age | is_active<br>---|---------|-----|----------<br>1  | unknown | 25  | true       &lt;-- initial-default applied at read time<br>2  | unknown | 25  | true       &lt;-- write-default physically written to Parquet</pre><h4>Modifying Defaults Over Time</h4><p>When a default value definition is updated, the engine modifies the write-default property for future writes while strictly preserving the initial-default established during the initial column addition.</p><pre>-- Update the write-default for the age column<br>ALTER TABLE ice_parq CHANGE COLUMN age age int DEFAULT 21;</pre><p>Insert a record:</p><pre>-- Insert a new record<br>INSERT INTO ice_parq (id) VALUES (3);</pre><p>Query the table:</p><pre>SELECT * FROM ice_parq ORDER BY id;</pre><p><em>Final Output:</em></p><pre>id | name    | age | is_active<br>---|---------|-----|----------<br>1  | unknown | 25  | true       &lt;-- Resolves via initial-default<br>2  | unknown | 25  | true       &lt;-- Persisted in data file via previous write-default<br>3  | unknown | 21  | true       &lt;-- Persisted in data file via new write-default</pre><p>This explicit decoupling of read-time and write-time defaults allows schemas to evolve safely and instantly at scale, ensuring historical data remains accurate without requiring backfill jobs.</p><h3>Conclusion</h3><p>The integration of Apache Iceberg V3 into the upcoming Apache Hive 4.3.x release represents a fundamental maturation of the data lakehouse architecture. We are moving away from costly downstream workarounds and baking critical capabilities directly into the execution engine. Between the I/O optimizations of Deletion Vectors, the deterministic CDC capabilities of Row Lineage, the flexibility of the Variant type, nanosecond precision, and the zero-downtime evolution of the dual-default system, data engineers now have an uncompromising, highly performant toolkit.</p><p>Get ready to upgrade your tables, experiment with these features, and enjoy the performance and usability boosts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d33483ab0977" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Basic Variant DataType Support in Apache Hive with Apache Iceberg]]></title>
            <link>https://medium.com/@ayushtkn/basic-variant-datatype-support-in-apache-hive-with-apache-iceberg-93c8518fcea9?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/93c8518fcea9</guid>
            <category><![CDATA[apache-hadoop]]></category>
            <category><![CDATA[data-ware-housing]]></category>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[apache-iceberg]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 11:36:02 GMT</pubDate>
            <atom:updated>2025-11-17T15:14:24.138Z</atom:updated>
            <content:encoded><![CDATA[<p><em>by </em><a href="https://www.linkedin.com/in/ayush151/"><em>Ayush Saxena</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dqp2STMP2TkynS8aXlLITw.png" /><figcaption>Basic Variant DataType Support in Apache Hive with Apache Iceberg</figcaption></figure><p>Semi-structured data has become central to modern analytics pipelines. Whether data arrives from APIs, clickstream events, IoT telemetry, ML metadata, or deeply nested operational logs, its structure evolves constantly — and rigid table schemas often become a bottleneck.</p><p>Apache Iceberg introduced the <strong>Variant</strong> data type to address this growing need: a flexible, efficient, strongly-typed representation for JSON-like data.<br>With Iceberg Format v3, Apache Hive now supports <strong>reading, writing, and querying Variant values</strong>, enabling more natural handling of evolving semi-structured datasets.</p><p>This article covers:</p><ul><li>What Variant is?</li><li>Why it matters?</li><li>Hive UDFs for working with Variant</li><li>End-to-end examples (create, insert, query, update, delete)</li><li>Practical patterns for real-world workloads</li></ul><h3>1. What Is Variant?</h3><p><strong>Variant</strong> is Iceberg’s native type designed to store:</p><ul><li>JSON objects</li><li>arrays</li><li>primitive values</li><li>arbitrary nesting</li></ul><p>It behaves like JSON, but with:</p><ul><li>binary-efficient storage</li><li>predictable typing</li><li>compatibility across execution engines</li><li>safer schema evolution</li></ul><h3>Example Variant payload</h3><pre>{<br>  &quot;action&quot;: &quot;purchase&quot;,<br>  &quot;amount&quot;: 1499,<br>  &quot;metadata&quot;: {<br>    &quot;device&quot;: {&quot;os&quot;: &quot;Android&quot;, &quot;version&quot;: &quot;15&quot;},<br>    &quot;location&quot;: {&quot;lat&quot;: 12.91, &quot;long&quot;: 77.63}<br>  }<br>}</pre><h3>2. Why Variant Matters</h3><h3>✔ Schema flexibility</h3><p>Semi-structured data changes frequently; Variant lets tables evolve without repeated ALTER TABLE operations.</p><h3>✔ Efficient storage</h3><p>Unlike storing JSON strings, Iceberg encodes Variant compactly in Parquet/Avro.</p><h3>✔ Better query performance</h3><p>Typed access via UDFs enables engines to optimize pushdown over time.</p><h3>✔ Cross-engine interoperability</h3><p>Spark, Flink, Trino, and now Hive share a common Variant implementation.</p><h3>3. Hive UDFs for Working with Variant</h3><p>Hive offers a focused set of UDFs for Variant support:</p><h3>1️⃣ parse_json(string)</h3><p>Parse a JSON string into a Variant value.</p><pre>SELECT parse_json(&#39;{&quot;x&quot;: 10, &quot;y&quot;: &quot;hello&quot;}&#39;);</pre><h3>2️⃣ to_json(variant)</h3><p>Convert a Variant value back to JSON text.</p><pre>SELECT to_json(event);</pre><h3>3️⃣ variant_get(variant, path)</h3><p>Retrieves a nested field using a <strong>JSONPath-like</strong> expression.</p><pre>SELECT variant_get(event, &#39;$.metadata.device&#39;);</pre><h3>4️⃣ try_variant_get(variant, path)</h3><p>Safe version — returns NULL instead of an error when the field is malformed.</p><pre>SELECT try_variant_get(event, &#39;$.metadata.location.lat&#39;);</pre><h3>✔ Path Syntax (Important!)</h3><p>Variant paths <strong>must start with </strong><strong>$</strong>, the root pointer.</p><p>Valid paths:</p><pre>$.action<br>$.metadata.device.os<br>$.metadata.coords.x<br>$[0]<br>$.items[2].id</pre><h3>4. End-to-End Tutorial</h3><p>A hands-on walkthrough of using Variant in a Hive Iceberg table.</p><h3>4.1 Creating a Table with Variant</h3><pre>CREATE TABLE user_events (<br>  user_id BIGINT,<br>  event VARIANT<br>)<br>STORED BY ICEBERG tblproperties(&#39;format-version&#39;=&#39;3&#39;);</pre><h3>4.2 Inserting Variant Data</h3><h3>Simple event</h3><pre>INSERT INTO user_events VALUES<br>(1, parse_json(&#39;{&quot;action&quot;:&quot;login&quot;,&quot;method&quot;:&quot;password&quot;}&#39;));</pre><h3>Nested event</h3><pre>INSERT INTO user_events VALUES<br>(2, parse_json(&#39;{<br>  &quot;action&quot;: &quot;click&quot;,<br>  &quot;timestamp&quot;: 1731523344,<br>  &quot;metadata&quot;: {<br>    &quot;coords&quot;: {&quot;x&quot;: 87, &quot;y&quot;: 192},<br>    &quot;device&quot;: {&quot;os&quot;:&quot;iOS&quot;,&quot;version&quot;:&quot;17.2&quot;},<br>    &quot;session&quot;: &quot;A92X&quot;<br>  }<br>}&#39;));</pre><h3>4.3 Querying Variant Fields</h3><h3>Extract a top-level field</h3><pre>SELECT<br>  user_id,<br>  variant_get(event, &#39;$.action&#39;) AS action<br>FROM user_events;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4c5EyfQaVTKni2kzNZ_ujg.png" /><figcaption>Query Output for fetching top-level field</figcaption></figure><h3>Extract nested fields</h3><pre>SELECT<br>  user_id,<br>  variant_get(event, &#39;$.metadata.device.os&#39;) AS os <br>FROM user_events where user_id=2;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkMcxVGhcEqOpVkFcV5-Xg.png" /><figcaption>Query Output for fetching nested-level field</figcaption></figure><h3>Safe access (avoid any errors)</h3><pre>SELECT<br>  user_id,<br>  try_variant_get(event, &#39;$.metadata.session&#39;) AS session_id<br>FROM user_events;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLu-XYG8a71Jrrw7CUvmkQ.png" /><figcaption>Query Output for fetching with safe access</figcaption></figure><p>In the above case for user_id: 1 there was no session_id but since we used try_variant_get() it returns null</p><h3>Use Variant in filters</h3><pre>SELECT user_id, to_json(event)<br>FROM user_events<br>WHERE variant_get(event, &#39;$.action&#39;) = &#39;click&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Btl2v3-HYrXlW54S6CPRhw.png" /><figcaption>Output from Variant in Filters</figcaption></figure><h3>4.4 Updating Variant Values</h3><p>Variant cannot be updated in-place (no JSON patch yet).<br>Updates replace the entire Variant field.</p><h3>Overwrite event</h3><pre>UPDATE user_events<br>SET event = parse_json(&#39;{&quot;action&quot;:&quot;logout&quot;}&#39;)<br>WHERE user_id = 1;</pre><h3>Add a new field (simple JSON manipulation trick)</h3><pre>UPDATE user_events<br>SET event = parse_json(<br>  CONCAT(<br>    REGEXP_REPLACE(to_json(event), &#39;\\}$&#39;, &#39;&#39;),<br>    &#39;, &quot;new_field&quot;: &quot;value&quot;}&#39;<br>  )<br>)<br>WHERE user_id = 2;</pre><p><em>“This is a simple string-manipulation approach for demonstration. For production use, a more robust method, potentially using a UDF, is recommended.”</em></p><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbL_pXnHVlHufONWcU0S5w.png" /><figcaption>Output after manipulation of Variant Fields</figcaption></figure><h3>4.5 Deleting Rows Using Variant</h3><pre>DELETE FROM user_events<br>WHERE variant_get(event, &#39;$.action&#39;) = &#39;login&#39;;</pre><h3>5. When Should You Use Variant?</h3><h3>✔ When schema evolution is frequent</h3><p>Clickstream, IoT, API ingestion, metadata-heavy workloads.</p><h3>✔ When flexibility is required, but strict JSON strings are inefficient</h3><p>Variant keeps data typed, structured, and queryable.</p><h3>✔ When you want Iceberg-native binary encoding</h3><p>Better storage + compatibility.</p><h3>✔ When workflows span multiple engines</h3><p>Spark ↔ Hive ↔ Flink ↔ Trino all interoperate via Variant.</p><h3>6. Final Thoughts</h3><p>Variant support significantly modernizes Hive’s ability to work with semi-structured data. Instead of storing raw JSON strings or managing endlessly changing nested schemas, Variant provides:</p><ul><li>Flexibility</li><li>Strong typing</li><li>Efficient storage</li><li>Cleaner SQL</li><li>Cross-engine compatibility</li></ul><p>Combined with parse_json, to_json, variant_get, and try_variant_get, Hive now offers a complete toolkit for navigating JSON-like structures using Iceberg’s standardized Variant representation.</p><blockquote><strong><em>Note:</em></strong><em> Variant support is available in Hive 4.2+.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93c8518fcea9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hive 4.1.x With OpenTelemetry]]></title>
            <link>https://medium.com/@ayushtkn/hive-4-1-x-with-opentelemetry-ca7624e55ec0?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca7624e55ec0</guid>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 08:37:03 GMT</pubDate>
            <atom:updated>2025-01-09T11:45:38.655Z</atom:updated>
            <content:encoded><![CDATA[<p><em>by </em><a href="https://www.linkedin.com/in/ayush-saxena151/"><em>Ayush Saxena</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gC0LN9MLHLz_bma9ITp7KA.jpeg" /><figcaption>Apache 4.1.x With OpenTelemetry</figcaption></figure><h3><strong>Scope</strong></h3><p>The goal is to demonstrate how to integrate metrics — covering both infrastructure and workload — and query data into an observability framework using OpenTelemetry in Hive 4.1.x.</p><h3>Use Cases for Observability Integration</h3><ul><li><strong>Metrics Data in Observability</strong></li></ul><p>A subset of infrastructure and workload metrics about HiveSever2 are transmitted to the observability platform in real-time.</p><p>The following HiveServer2 metrics are exposed through the OpenTelemetry (OTEL) framework:</p><p><strong>— Memory Usage:</strong></p><pre>memNonHeapUsedMGauge<br>memNonHeapCommittedM<br>memNonHeapMaxM<br>memHeapUsedM<br>memHeapCommittedM<br>memHeapMaxM<br>memMaxM</pre><p><strong>— ThreadCounts:</strong></p><pre>threadsNew<br>threadsRunnable<br>threadsBlocked<br>threadsWaiting<br>threadsTimedWaiting<br>threadsTerminated</pre><p><strong>— OsLevel: </strong><em>(Only Applicable for UnixBased OS)</em></p><pre>systemCpuLoad<br>committedVirtualMemorySize<br>processCpuTime<br>freePhysicalMemorySize<br>freeSwapSpaceSize<br>totalPhysicalMemorySize<br>processCpuLoad</pre><ul><li><strong>Query Data in Observability</strong></li></ul><p>Real-time data regarding key events in the lifecycle of both actively running and completed queries are sent to the observability platform.</p><p>The following query-related details are exposed via the OTEL framework from HiveServer2:</p><p><strong>— Query Level:</strong></p><ul><li><em>For Live Queries</em></li></ul><pre>QueryId<br>QueryString<br>UserName<br>ExecutionEngine<br>ErrorMessage</pre><ul><li><em>For Completed Queries</em></li></ul><pre>QueryId<br>QueryStartTime<br>EndTime<br>OperationId<br>OperationLogLocation<br>ErrorMessage<br>ExplainPlan<br>FullLogLocation<br>Running<br>Runtime<br>UserName<br>ExecutionEngine<br>State<br>SessionId</pre><p><strong>— Task Level </strong><em>(For each task)</em><strong>:</strong></p><pre>TaskId<br>Name<br>TaskType<br>Status<br>StatusMessage<br>ExternalHandle<br>ErrorMsg<br>ReturnValue<br>BeginTime<br>ElapsedTime<br>EndTime</pre><h3><strong>Configuring OpenTelemetry in HiveServer2</strong></h3><p>To enable OpenTelemetry (OTEL) data collection in HiveServer2, the following parameters need to be configured:</p><p><strong>— hive.otel.metrics.frequency.seconds</strong>: The interval at which metrics are collected. It should be set to a value greater than 0, such as 2s or 10s, to ensure metrics are gathered at regular intervals.</p><p><strong>— hive.otel.collector.endpoint: </strong>The endpoint where all OTLP traces, metrics, and logs will be sent. Typically, it is the address of an OpenTelemetry Collector. The endpoint must be a valid URL with a scheme of either http or https, depending on whether TLS is enabled.</p><p>In addition to these core settings, you can optionally adjust the following configuration parameters to further optimize the setup:</p><p><strong>— hive.otel.exporter.timeout: </strong><em>(Default: 10m) </em>The maximum amount of time allowed for the OTEL exporter to complete an export operation. If the operation exceeds this duration, it will time out.</p><p><strong>— hive.otel.retry.initial.backoff: </strong><em>(Default: 10s) </em>The initial delay before the first retry attempt in case of a failure in the OTEL exporter. This value serves as the starting point for the exponential backoff strategy.</p><p><strong>— hive.otel.retry.max.backoff: </strong><em>(Default: 1m) </em>The maximum time to wait between retries for the OTEL exporter. This sets an upper limit on the backoff interval, ensuring retries do not exceed this duration even with exponential backoff.</p><p><strong>— hive.otel.retry.backoff.multiplier: </strong><em>(Default: 5) </em>The multiplier applied to the backoff interval for retries in the OTEL exporter. This determines how much the backoff interval increases after each failed attempt, following an exponential backoff strategy.</p><h3>Setting Up OpenTelemetry with Docker</h3><p>To try OpenTelemetry in Hive using Docker, follow these steps:</p><ol><li><strong>Download the Docker Compose Zip</strong><br>Run the following command to download the Docker Compose zip:</li></ol><pre>wget https://raw.githubusercontent.com/ayushtkn/hive/otel/packaging/src/otel-docker.zip</pre><p><strong>2. Unzip the Downloaded File</strong><br>Unzip the downloaded zip file:</p><pre>unzip otel-docker.zip</pre><p><strong>3. Navigate to the Unzipped Directory &amp; Start Docker</strong><br>Go to the extracted directory and run Docker Compose:</p><pre>cd docker<br>docker-compose up -d</pre><p><strong>4. Access Beeline &amp; Execute Queries</strong><br>Enter Beeline and execute some Hive queries:</p><pre>docker exec -it hiveserver2 beeline -u &#39;jdbc:hive2://localhost:10000/&#39;</pre><p>Run a few generic Hive queries.<br><strong><em>Note:</em></strong><em> If you encounter a “Connection Refused” exception, it means HiveServer2 hasn’t started yet. Retry after a brief wait.</em></p><p><strong>5. Access Query Data via Jaeger UI</strong><br>You can access the Jaeger UI at:<br><a href="http://localhost:16686/">http://localhost:16686/</a></p><ul><li>Select the service “Hive-otel” and click on <strong>Find Traces</strong>.</li><li>You’ll see traces for queries. Completed queries will have the suffix -completed, while running queries would be just query id without any suffix.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i93DoCrl4CmZIfjBrFllyg.png" /><figcaption>Jaeger UI showing 4 queries, 1 live &amp; 3completed</figcaption></figure><ul><li>Click on any span to view detailed attributes or task information related to the query.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYNPkBt_rV6ciroXKS7uUw.png" /><figcaption>Expanded view for One Completed Query</figcaption></figure><p>For failed queries the ErrorMessage would be shown in the expanded view</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5CMjodXTScwn8s8w7IdTA.png" /><figcaption>Expanded view for One Failed Query</figcaption></figure><p><strong>6. Setting Up Grafana</strong></p><ul><li>Log in to Grafana at: <a href="http://localhost:3000/">http://localhost:3000/</a></li><li>Username: admin</li><li>Password: admin</li><li>Go to the <strong>Data Sources</strong> section under the <strong>Configuration</strong> tab.</li><li>Select <strong>Prometheus</strong> and set the name as Prometheus. (<em>Case Sensitive</em>)</li><li>Under the <strong>Prometheus server URL</strong>, set: <a href="http://prometheus:9090/">http://prometheus:9090/</a></li><li>Click <strong>Save</strong>.</li><li>Go to the <strong>Dashboards</strong> section and click on <strong>Create Dashboard</strong>.</li><li>Select <strong>Import Dashboard</strong>, click <strong>Upload Dashboard JSON file</strong>, and upload the file HS2_DASHBOARD.jsonfound in the zip.</li><li>After uploading, go back to the <strong>Dashboards</strong> section, refresh, and you should see the metrics displayed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hzApJxmOsi9o0Y0K-4aTA.png" /><figcaption>Grafana Dashboard Showing HiveServer2 Metrics</figcaption></figure><p><strong>Notes:</strong></p><ul><li>This blog demonstrates the use of Jaeger UI and Prometheus/Grafana as OpenTelemetry (OTEL) collectors for HiveServer2. However, any OTEL-compatible collector, such as Zipkin or others, can be integrated seamlessly with HiveServer2.</li><li>The feature is slated for official availability in the Hive 4.1 release, expected around mid-2025.</li><li>While the configurations in this blog are geared towards quick experimentation, production setups should ensure secure endpoints, optimized performance, and adherence to enterprise observability standards.</li><li>The Docker image is intended solely for demonstration purposes and is not recommended for production use.</li></ul><p><strong>*********************************** End ***********************************</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca7624e55ec0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Hive-4.x with Iceberg Branches & Tags]]></title>
            <link>https://medium.com/@ayushtkn/apache-hive-4-x-with-iceberg-branches-tags-3d52293ac0bf?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d52293ac0bf</guid>
            <category><![CDATA[apache-hadoop]]></category>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[apache-iceberg]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[apache-hive]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Tue, 19 Sep 2023 04:36:01 GMT</pubDate>
            <atom:updated>2024-04-26T21:59:17.808Z</atom:updated>
            <content:encoded><![CDATA[<p><em>by </em><a href="https://www.linkedin.com/in/ayush151/"><em>Ayush Saxena</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEYof_IlprAniz5pHmOgMQ.png" /><figcaption>Apache Iceberg Branch &amp; Tags With Apache Hive 4.x</figcaption></figure><h3><strong>Introduction:</strong></h3><p>For sophisticated snapshot lifecycle management, Iceberg supports branches and tags which are named references to snapshots with their own independent lifecycles. This lifecycle is controlled by branch and tag level retention policies. Branches are independent lineages of snapshots and point to the head of the lineage.</p><h3><strong>Prerequisites:</strong></h3><p>Working knowledge of Apache Hive &amp; Apache Iceberg. If not, can read <a href="https://medium.com/@ayushtkn/apache-hive-4-x-with-apache-iceberg-part-i-355e7a380725">here</a></p><h3><strong>Initial Setup:</strong></h3><ul><li>Create a docker env with version: <strong>4.0.0</strong>, Read (<a href="https://iceberg.apache.org/hive-quickstart/">Hive Iceberg Docker QuickStart</a>) for steps to create a docker environment. Specify the version as <strong>4.0.0</strong></li><li>Create an iceberg table:</li></ul><pre>CREATE TABLE test (ID INT) STORED BY ICEBERG TBLPROPERTIES(&#39;format-version&#39;=&#39;2&#39;);</pre><ul><li>Insert some data to generate multiple snapshots:</li></ul><pre>INSERT INTO test VALUES (1), (2);<br>INSERT INTO test VALUES (3), (4);<br>INSERT INTO test VALUES (5), (6);<br>INSERT INTO test VALUES (6), (7);</pre><ul><li>Fetch the list of snapshots corresponding to the iceberg table</li></ul><pre>SELECT * FROM default.test.history;</pre><p>The above will list the snapshots corresponding to the table which can be used for creating branches &amp; Tags.</p><p><strong>Sample output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D5e161HlYVVwHgtN1YWAzg.png" /><figcaption>Snapshot History for table test</figcaption></figure><p><strong>Note:</strong><em> The snapshot id &amp; the timestamp will be different for everyone.</em></p><h3><strong>Creating a branch:</strong></h3><p>A branch can be created from a table via a simple Alter Table… Create Branch… statement specifying the table &amp; branch name along side either the System Version or the System Time corresponding to the snapshot which should act as the HEAD of the branch.</p><ul><li>Creating using <strong>SYSTEM_VERSION</strong>:</li></ul><pre>ALTER TABLE test CREATE BRANCH branch1 FOR SYSTEM_VERSION AS OF 3369973735913135680;</pre><p>The above creates a branch named branch1 from table test corresponding to the specified snapshot id(Second in the history table).</p><ul><li>Creating using <strong>SYSTEM_TIME</strong>:</li></ul><pre>ALTER TABLE test CREATE BRANCH branch2 FOR SYSTEM_TIME AS OF &#39;2023-09-16 09:46:38.939 Etc/UTC&#39;;</pre><p>The above creates a branch named branch2 from table test corresponding to the state of the table at the specified timestamp. (Third in the history table)</p><ul><li>Creating with <strong>default configurations</strong>:</li></ul><p>In case no arguments are provided to specify the snapshot version, a branch can be created which points to current main branch(current state of table) of the iceberg table.</p><pre>ALTER TABLE test CREATE BRANCH branch3;</pre><p>The above creates a branch named branch3 which is in same state as the current table test.</p><ul><li>Optionally the number of snapshot retentions per branch can be specified while creating a branch like:</li></ul><pre>ALTER TABLE test CREATE BRANCH branch4 FOR SYSTEM_VERSION AS OF 3369973735913135680 with SNAPSHOT RETENTION 5 SNAPSHOTS;</pre><h3><strong>Listing created Branches &amp; Tags:</strong></h3><p>The created branches &amp; Tags can be listed using the refs metadata table of iceberg.</p><pre>select * from default.test.refs;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1qWosxIhFBwIQFaXHptzkg.png" /><figcaption>List of branches &amp; Tags</figcaption></figure><h3><strong>Writing into the Branch:</strong></h3><p>Data can be ingested into an iceberg table branch similarly as it would be done in case of normal iceberg table. In the queries the name of the branch needs to be specified in following manner.</p><p>&lt;<em>Database Name</em>&gt;.&lt;<em>Table Name</em>&gt;.branch_&lt;<em>Branch Name</em>&gt;</p><ul><li><strong>Insert</strong> into a branch</li></ul><pre>INSERT INTO TABLE default.test.branch_branch1 VALUES (10, 11);</pre><p>The above inserts values into the ‘branch1’ of table ‘test’ in ‘default’ database</p><ul><li><strong>Update</strong> values in a branch</li></ul><pre>UPDATE TABLE default.test.branch_branch1 SET ID=20 WHERE ID=10;</pre><p>The above query updates the values in ‘branch1’ of table ‘test’ in ‘default’ database.</p><ul><li><strong>Delete</strong> values in a branch</li></ul><pre>DELETE FROM default.test.branch_branch1 WHERE ID=11;</pre><p>The above query deleles the specified value in ‘branch1’ of table ‘test’ in ‘default’ database.</p><p><strong>→ <em>Apart from these all other queries like Merge/IOW/Load are supported with iceberg branches </em>←</strong></p><h3><strong>Querying a Branch:</strong></h3><p>An iceberg branch supports all query statements like any other hive table.</p><p>Example:</p><pre>select * from default.test.branch_branch1;</pre><p>Sample output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9olcmx5w55oypkZeLrYUQ.png" /><figcaption>Output of branch1 of test table</figcaption></figure><p><strong>→ <em>Apart from this all other read queries are supported with iceberg branches</em>←</strong></p><h3><strong>Fast-Forward a Branch:</strong></h3><p>An iceberg branch which is an ancestor of another branch can be fast-forwarded to the state of the other branch.</p><p>Example:</p><p>Insert some data into main branch</p><pre>INSERT INTO test values (55), (66);</pre><p>Now fast-forward the previouslly created branch3 to the current main branch</p><pre>ALTER table test EXECUTE FAST-FORWARD &#39;branch3&#39; &#39;main&#39;;</pre><p>This fast-forwards the branch3 to the state of main. Querying branch3 now would show the newly inserted records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LeaAO2-UFbXp_j8yLQICuA.png" /><figcaption>Output of branch3 after being fast-forwarded to main branch</figcaption></figure><p>In case the second branch name is not specified the main branch gets fast-forwaded to the branch specified.</p><p>Example-2:</p><p>Delete some values from ‘branch3&#39;</p><pre>DELETE FROM default.test.branch_branch3 WHERE ID=66;</pre><p>Fast-Forward the main branch to the state of branch3</p><pre>ALTER table test EXECUTE FAST-FORWARD &#39;branch3&#39;;</pre><p>The above fast-forwards the main branch of the table test to the state of branch3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoiJpyinGdve4hM549e3Pg.png" /><figcaption>Output of main branch of table test after being fast-forwarded to branch3</figcaption></figure><h3><strong>Cherry-Pick into a Branch:</strong></h3><p>Cherry-pick of commits as of now is supported only on the main branch of an iceberg table.</p><p>So, if we rollback to a previous commit &amp; we want to just pull in changes from a single commit from future states we can cherry-pick that commit.</p><p>Example:</p><p>Fetch the current history of the table:</p><pre>SELECT * FROM default.test.history;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vLC5Nnj9YDxZV34Y3g5xYA.png" /><figcaption>History of the table test</figcaption></figure><p>Rollback the current table:</p><pre>ALTER table test EXECUTE ROLLBACK (3369973735913135680);</pre><p>The above rollbacks the main table to the second snapshot in the history list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHaXlhiBGb9uytaugnBBfw.png" /><figcaption>Output of table test after rollback</figcaption></figure><p>Cherry-Pick the second last snapshot from the history table which inserted 55 &amp; 56</p><pre> ALTER table test EXECUTE CHERRY-PICK 8602659039622823857;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vb35BOkZVoKNwtRpmcPAcg.png" /><figcaption>Output of table after cherry-pick</figcaption></figure><h3><strong>Deleting a Branch:</strong></h3><p>An iceberg branch can be deleted like:</p><pre>ALTER TABLE test DROP BRANCH branch1;</pre><p>The above query drops the ‘branch1’ of table test.</p><p>The drop branch syntax supports ‘<em>IF EXISTS</em>’ clause as well, to prevent errors if the branch is already deleted or doesn’t exist. Like:</p><pre>ALTER TABLE test DROP BRANCH IF EXISTS branch1;</pre><h3><strong>Creating a Tag:</strong></h3><p>A tag can be created from a table using the Alter table…Create Tag statements and by specifying the table &amp; branch name along side either the System_version or the System_time corresponding to the snapshot which the tag should refer to.</p><ul><li>Creating using <strong>SYSTEM_VERSION</strong>:</li></ul><pre>ALTER TABLE test CREATE TAG tag1 FOR SYSTEM_VERSION AS OF 3369973735913135680;</pre><p>The above creates a tag named tag1 from table test corresponding to the specified snapshot id(Second in the history table).</p><ul><li>Creating using <strong>SYSTEM_TIME</strong>:</li></ul><pre>ALTER TABLE test CREATE TAG tag2 FOR SYSTEM_TIME AS OF &#39;2023-09-16 09:46:38.939 Etc/UTC&#39;;</pre><p>The above creates a tag named tag2 from table test corresponding to the state of the table at the specified timestamp. (Third in the history table)</p><ul><li>Creating with <strong>default configurations</strong>:</li></ul><p>In case no arguments are provided to specify the snapshot version, a branch can be created which points to current main branch(current state of table) of the iceberg table.</p><pre>ALTER TABLE test CREATE TAG tag3;</pre><p>The above creates a tag named tag3 which is in same state as the current table test.</p><h3><strong>Querying a Tag:</strong></h3><p>The iceberg tags supports all kinds of read queries, the queries can be performed by specifying the tag name instead of the table name in the following format.</p><p>&lt;<em>Database Name</em>&gt;.&lt;<em>Table Name</em>&gt;.tag_&lt;<em>Tag Name</em>&gt;</p><p>Example:</p><pre>SELECT * FROM default.test.tag_tag1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3RZb_aisDLgfSsiP6inVxw.png" /><figcaption>Output of tag1 of table test</figcaption></figure><h3><strong>Deleting a Tag:</strong></h3><p>An iceberg tag can be deleted like:</p><pre>ALTER TABLE test DROP TAG tag1;</pre><p>The above query drops the tag1 corresponding to the table test.</p><p>The drop tag syntax supports ‘IF EXISTS’ clause as well, to prevent errors if the tag is already deleted or doesn’t exist. Like:</p><pre>ALTER TABLE test DROP TAG IF EXISTS tag1;</pre><h3><strong>Release:</strong></h3><p>The blog mentions features being part of Apache Hive-4.0.0 release</p><p><strong>Note: </strong>The docker images are meant only for dev. usage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d52293ac0bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Hive 4.x With Apache Iceberg(Part-I)]]></title>
            <link>https://medium.com/@ayushtkn/apache-hive-4-x-with-apache-iceberg-part-i-355e7a380725?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/355e7a380725</guid>
            <category><![CDATA[icebergs]]></category>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 16:39:41 GMT</pubDate>
            <atom:updated>2024-06-19T08:19:26.007Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Hive 4.x With Apache Iceberg (Part-I)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vs8RISJE4KkOwQzpG-ZdJw.png" /><figcaption>Apache Hive 4.x + Apache Iceberg 1.3.0</figcaption></figure><p><strong>Introduction to Iceberg in Hive:</strong></p><p>Iceberg is an open table format designed for large analytic workloads. It uses snapshots to store modifications to tables and provides several niche features like Time Travel, Partition/Schema Evolution and many others. Hive 4.x provides a way to use the iceberg table format out of the box like a normal hive table.</p><p>Here we will be looking at some basic stuff towards getting started with Iceberg in Hive &amp; some latest stuff being introduced for iceberg in Apache 4.x release.</p><p><strong>Creating an Iceberg table:</strong></p><p>An iceberg table can be created like normal Hive tables by just specifying the “Stored by Iceberg” clause in the queries</p><ul><li><strong>Using the create statement:</strong></li></ul><pre>create external table test_iceberg(id int, value string) stored by iceberg;</pre><ul><li><strong>Using CTAS:</strong></li></ul><pre>create external table tbl_ice stored by iceberg tblproperties (&#39;format-version&#39;=&#39;2&#39;) as<br>select * from source;</pre><ul><li><strong>Using CTLT:</strong></li></ul><pre>create external table iceberg_ctlt like acid_table stored by iceberg;</pre><p>The source of CTAS/CTLT table can be either an external or a managed table.</p><p><strong>Migrating an Existing Table to Iceberg:</strong></p><p>Existing Hive external tables can be easily converted into iceberg tables by using the Alter queries with “Convert To Iceberg” clause</p><pre>ALTER TABLE tableName CONVERT TO ICEBERG;</pre><p>As of now only external tables can be converted to iceberg tables directly.</p><p><strong>Ingesting data to Iceberg tables</strong></p><p>Data can be ingested to iceberg tables like normal hive tables, Hive allows almost all ways of inserting data to iceberg tables like, Insert queries/Insert-Overwrite and now from Hive-4.x the LOAD queries as well.</p><ul><li><strong>Using the Load queries:</strong></li></ul><p>Iceberg LOAD queries for tables which haven’t undergone Schema/Partition evolution, hive directly uses the Iceberg Append API which prevents rewrite of the data files.</p><p>Example:</p><pre>LOAD DATA LOCAL INPATH &#39;/data/files/doctors.avro&#39; OVERWRITE INTO TABLE ice_avro;</pre><ul><li><strong>Load with partition clause</strong></li></ul><pre>LOAD DATA LOCAL INPATH &#39;/data/files/parquet_partition/pcol=100&#39; INTO TABLE<br>ice_parquet_partitioned PARTITION (pcol=&#39;100&#39;);</pre><p><em>If the config “hive.load.data.use.native.api” is set to “false”, hive will rather than using the Append api, will launch a Tez job to do the LOAD.</em></p><p><strong>Reading Iceberg tables:</strong></p><p>Hive supports all kinds of read queries on the iceberg table like any other hive managed tables. The iceberg table can be queried like a normal hive table. like:</p><pre>SELECT * FROM iceberg_table where id=10;</pre><p>Hive supports both Vectorized &amp; Non-Vectorized modes of reading iceberg tables.</p><p><strong>Snapshot Management:</strong></p><p>Hive provides several ways to play with the iceberg snapshots</p><ul><li><strong>Set current snapshot:</strong></li></ul><pre>ALTER TABLE iceberg_table EXECUTE SET_CURRENT_SNAPSHOT(&lt;snapshotId&gt;);</pre><p>The above sets the current snapshot of the table to the snapshot id provided.</p><ul><li><strong>Rollback Snapshot:</strong></li></ul><pre>ALTER TABLE tbl_ice EXECUTE ROLLBACK(&lt;snapshotId&gt;)</pre><p>The rollback commands, rollsback the table to a prior snapshot state of the table. <em>(The Rollback commands was added prior to SET_CURRENT_SNAPSHOT, which can be used to achieve same results)</em></p><ul><li><strong>Expire Snapshots:</strong></li></ul><p>Hive provides several ways to expire a snapshot:</p><ul><li>Specifying a list of snapshots to expire:</li></ul><pre>ALTER TABLE iceberg_table EXECUTE EXPIRE_SNAPSHOTS(&#39;&lt;comma seperated list of snapshot ids&gt;&#39;)</pre><ul><li>Expiring Snapshots older than a particular timestamp</li></ul><pre>ALTER TABLE iceberg_table EXECUTE EXPIRE_SNAPSHOTS(&#39;&lt;timestamp&gt;&#39;);</pre><p><strong>Time Travel:</strong></p><p>Iceberg tables can be queried to get the state of a the table from past. Time travel queries can be performed by either using a snapshot id or a timestamp</p><ul><li>Using timestamp:</li></ul><pre>SELECT * FROM tableName <br>FOR SYSTEM_TIME AS OF &#39;&lt;TIMESTAMP&gt;&#39;;</pre><ul><li>Using snapshot id:</li></ul><pre>SELECT * FROM tableName FOR SYSTEM_VERSION AS OF &lt;Snapshot Id&gt;</pre><p><strong>Coming in Next Sections?</strong></p><ul><li>Materialized Views &amp; Iceberg</li><li><a href="https://medium.com/@ayushtkn/apache-hive-4-x-with-iceberg-branches-tags-3d52293ac0bf">Branches &amp; Tags</a> (<em>Published</em>)</li><li>More advanced ways of playing with snapshots</li><li>Getting started with Hive-Iceberg with Docker</li><li>Metadata Tables &amp; Operations around them</li><li>Specifics around Iceberg V2 tables</li><li>Performance Comparisons with Iceberg Tables.</li></ul><p>Release:</p><p>The blog mentions features being part of Apache Hive-4.0.0 release</p><p>— — — — — — — — — — — — — — END — — — — — — — — — — — — — — — — — — — -</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=355e7a380725" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Hive: ESRI GeoSpatial Support]]></title>
            <link>https://medium.com/@ayushtkn/apache-hive-esri-geospatial-support-5ca815daaa7e?source=rss-fcf2a5c2e85f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ca815daaa7e</guid>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[geospatial]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[apache-hadoop]]></category>
            <dc:creator><![CDATA[Ayush Saxena]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 03:56:43 GMT</pubDate>
            <atom:updated>2023-06-15T03:56:43.046Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is GeoSpatial?</strong></h3><p>In simple terms, “GEOSPATIAL INFORMATION” is geography and mapping. It is “place based” or “locational” information. It is data tied to a map and capable of being portrayed on a map. With the accumulation of vast quantities of location information, it has become very important to store and manage this information efficiently. When this information is used efficiently, it can provide many useful insights which could not be generated using raw data. When location information is tagged with normal data, it gives a different dimension to the analytics. The information is useful in different fields like fraud detection, user behaviour prediction, weather forecasting and many more. Due to the nonlinear nature of geospatial data, it can not be stored and processed as normal data. Special storage and indexing techniques are used to make the processing faster.</p><h3>GeoSpatial Data With Hive</h3><p>Hive provides adding ESRI based standard geospatial data directly into hive tables. It even provides several GeoSpatial UDFs which can be used to process the geospatial data and provide meaningful insights. Along with the capability to operate on these data, the geospatial data in hive tables can visualized graphically when linked to tools like PowerBI &amp; Tableau. These all capabilities are available in Hive out of the box. The UDFs are autogenerated by Hive. The user need not load the jars or create the functions. Hive internally manages these UDFs so that users need not worry about the compatibility between different versions. The data can be loaded from any of the standard formats like GeoJSON, WKB or WKT. Once the data is loaded, users can operate on this data by using the various inbuilt functions supported.</p><h3>Creating Tables Supporting GeoSpatial Data</h3><p>Tables supporting GeoSpatial data can be created normally like any other table. Just make the column that stores the GeoSpatial data a BINARY type. Natively creating Geometry/Geography type is not yet supported. Users can keep the geospatial data in other data types. Those fields can be combined using the UDF provided to form a Geometry type during query execution.</p><ul><li><strong>Table with double fields representing coordinates :</strong></li></ul><p>In the table below, the earthquake coordinates are stored as double fields. Table earthquakes stores the earthquake occurrence info backed by a CSV file.</p><pre>CREATE TABLE earthquakes (<br>      earthquake_date STRING,<br>      latitude DOUBLE,<br>      longitude DOUBLE,<br>      depth DOUBLE,<br>      magnitude DOUBLE,<br>      magtype string,<br>      mbstations string,<br>      gap string,<br>      distance string,<br>      rms string,<br>      source string,<br>      eventid string)<br>ROW FORMAT DELIMITED FIELDS TERMINATED BY &#39;,&#39;<br>STORED AS TEXTFILE;</pre><ul><li><strong>Table using binary columns to store Geometry data :</strong></li></ul><p>Binary fields can be used to load the data stored in standard geometry formats. A Hive provided Json serde can be used to load GeoJson data stored in a file to HIve. Data stored in KWT and KWB are loaded directly and do not need any serde to convert the data before loading. The counties table, stores the boundary info for each county backed by standard geospatial format “EnclosedEsriJsonInputFromat”. Column BoundaryShape stores the boundary of each county.</p><pre>CREATE TABLE counties (<br>        Area string,<br>        Perimeter string,<br>        State string,<br>        County string,<br>        Name string,<br>        BoundaryShape binary)                  <br>ROW FORMAT SERDE &#39;org.apache.hadoop.hive.ql.udf.esri.serde.EsriJsonSerDe&#39;<br>STORED AS<br> INPUTFORMAT &#39;org.apache.hadoop.hive.ql.io.esriJson.EnclosedEsriJsonInputFormat&#39;<br>OUTPUTFORMAT &#39;org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat&#39;;</pre><h3>Adding Data to the Tables</h3><p>Once the table is created, the data can be ingested into the tables using either direct inserts into the tables, or if the data is available in some standard geospatial formats, loaded using the load method.</p><ul><li><strong>Direct Inserts into the Tables:</strong></li></ul><p>To Insert data directly into the tables, we can run a normal insert query as follows</p><pre>INSERT INTO dist_binary          <br>    VALUES (<br>       ST_Point(12.5,16.2),<br>       ST_Point(18.7,4.5)<br>     );</pre><p>This query inserts two coordinates into the table. The ST_POINT(X,Y) is a hive provided UDF which converts the coordinate into GeoSpatial Standard binary format.</p><ul><li><strong>LOAD data into the tables from Standard GeoSpatial Data Files:</strong></li></ul><p>If the data is available in some standard data format in some external files, it can be directly loaded as follows</p><pre>LOAD DATA INPATH &#39;earthquake-demo/counties-data/california-counties.json&#39; <br>OVERWRITE INTO TABLE counties;</pre><h3>Operating/Querying the GeoSpatial Data:</h3><p>Hive provides a bunch of GeoSpatial UDFs which can be directly used for simple scenarios like calculating the distance between two points or clubbing them into complex GeoSpatial queries.</p><ul><li><strong>Calculating distance between 2 points:</strong></li></ul><pre>select<br> ST_AsText(pointa) as First_Point,<br> ST_AsText(pointb) as Second_Point,<br> ST_Length(ST_LineString(array(pointa,pointb))) as Distance<br> from dist_binary;</pre><p>This statement computes the distance between the two coordinates in a row.</p><p><strong>The output looks something like this:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*cbQuAUT3ytuoxa8SeGuKRQ.png" /></figure><ul><li><strong>Figuring out the number of earthquakes in a county using its coordinates</strong></li></ul><pre>  SELECT counties.name, count(*) cnt<br>    FROM counties<br>         JOIN earthquakes<br>    WHERE <br>       ST_Contains(counties.boundaryshape, <br>                             ST_Point(earthquakes.longitude, earthquakes.latitude))<br>    GROUP BY counties.name<br>    ORDER BY cnt desc;</pre><p>This calculates the number of earthquakes in various countries using the earthquake coordinates and countries geometry.</p><p><strong>The output looks something like this:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*owqGyGz9Ovc0GF0Nj3IF8w.png" /></figure><h3>Available Hive GeoSpatial UDFs</h3><p>The Hive Engine provides direct support for all the UDFs provided by ESRI. The list and details of which can be found at:</p><p><a href="https://github.com/Esri/spatial-framework-for-hadoop/wiki/UDF-Documentation">UDF Documentation</a></p><h3>Integrating with CDV/Tableau/PowerBI</h3><p><strong><em>Example Integrating with CDV</em></strong><em>(Cloudera Internal-Similar to PowerBI &amp; Tableau)</em></p><ul><li>Create a table to store the delay time and coordinates of Indian Airports:</li></ul><pre>create table india_airport_delays(name string, coordinate binary, delay int);</pre><ul><li>Insert some sample data into the table:</li></ul><pre>insert into india_airport_delays values<br>(&#39;Chandigarh Airport&#39;, ST_Point(30.667767, 76.786232), 8),<br>(&#39;Diu Airport&#39;, ST_Point(20.714273, 70.921616), 2),<br>(&#39;Kempegowda International Airport (BLR)&#39;, ST_Point(13.199379,77.710136), 11),<br>(&#39;Biju Patnaik International Airport (BBI), Bhubaneshwar&#39;, ST_Point( 20.254780 ,85.816521), 3),<br>(&#39;Visakhapatnam Airport, Andhra Pradesh,&#39;, ST_Point(17.728647,83.223549), 5),<br>(&#39;Indira Gandhi International Airport (DEL), New Delhi&#39;, ST_Point(28.556160,77.100281), 14),<br>(&#39;Chhatrapati Shivaji International Airport (BOM), Vile Parle East, Mumbai&#39;, ST_Point(19.097403,72.874245), 10),<br>(&#39;Sardar Vallabhbhai Patel International Airport, Ahmedabad&#39;, ST_Point(23.0734,72.6266), 7),<br>(&#39;Lucknow Airport&#39;, ST_Point(26.761,80.889), 6),<br>(&#39;Jaipur Airport&#39;, ST_Point(26.824,75.812), 4),<br>(&#39;Devi Ahilyabai Holkar Airport, Indore&#39;, ST_Point(23.0734,72.6266), 2),<br>(&#39;Guwahati Intl Airport&#39;, ST_Point(26.106,91.586), 6),<br>(&#39;Cuttack Airport&#39;, ST_Point(20.550,85.886), 7),<br>(&#39;Raxaul Airport, Ekderwa, Bihar,&#39;, ST_Point(26.996279,84.820374), 3);</pre><ul><li>Create a View using this table which can be used by CDV for visualization purpose:</li></ul><pre>create view india_airports as select name, ST_X(coordinate) as latitude, ST_Y(coordinate) as longitude, delay<br>from india_airport_delays;</pre><ul><li>Check the contents of the original table<em>(Optional)</em></li></ul><pre>select name, ST_AsText(coordinate), delay from india_airport_delays;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*YyedCS1nPoaNX23HIsza5g.png" /></figure><ul><li>Check the contents of the view. <em>(Optional)</em></li></ul><pre>select * from airports.india_airports;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udRLOfmdIaxCl5DCF7aFjw.png" /></figure><ul><li>Create a CDV connection and dataset using the View. Then create Visuals using normal CDV UI commands. (Different for PowerBI or Tableau)</li></ul><p><strong>Sample Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*4A10qwruNPjD732XxjgQvA.png" /></figure><p>The above adds 4 Visuals into the Dashboard. The above two Visuals are full displays of all the airports of India.</p><p>The Second row uses CDV filter on the delay column of the view to show only the Airports with a delay time of more than 5 Minutes.</p><p><strong>Magnified Output of Airport With Delay &gt; 5 Mins</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*QxiGSxBzh-Z2EaLj6t6acg.png" /></figure><h3>Future Scope</h3><ul><li>Add support for Native GeoSpatial data types, rather than storing them as Binary/Text</li><li>GeoSpatial data specific performance improvements.</li><li>Support for creating QuadTree dynamically during query processing.</li><li>Data partitioning on geometry column based on sample data.</li><li>CBO support for geometry type.</li><li>Connector for ArcGIS and QGis like tools.</li></ul><h3><strong>OpenSource Jira:</strong></h3><p><a href="https://issues.apache.org/jira/browse/HIVE-26222">Native GeoSpatial Support in Hive</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ca815daaa7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>