Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

help with Jolt tarnsformation

avatar
Expert Contributor

Hi All, 

Looking for some help with JOLT transformatio, which i am completely new.

my input JSON looks like this 

 

{
	"type": "delete",
	"timestamp": 1681484884000,
	"binlog_filename": "bin.000003",
	"binlog_position": 6378700,
	"database": "db1",
	"table_name": "records",
	"table_id": 108,
	"columns": [{
		"id": 1,
		"name": "id",
		"column_type": 4,
		"value": 259
	}, {
		"id": 2,
		"name": "index_id",
		"column_type": 4,
		"value": 1
	}, {
		"id": 3,
		"name": "state_id",
		"column_type": 4,
		"value": 1
	}]
}

This is from mysql binlogs.

 

I want to transform it to have a single field..

 

[{
	"id": 259
}]

 

from one of the tutorials here in cloudera comminity, i saw this JOLT transformation.

[
  {
    "operation": "shift",
    "spec": {
      "columns": {
        "*": {
          "@(value)": "[#1].@(1,name)"
        }
      }
    }
  }
]

 

But it gives all fileds.. but I just need one filed which is the ID. I need to drop rest all fields.. 

Can someone please help in this regards.

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi,

If you are looking to set the id value for the first element in the columns array you can use the following spec:

 

[
  {
    "operation": "shift",
    "spec": {
      "columns": {
        "0": {
          "value": "[].@(1,name)"
        }
      }
    }
  }
]

 

If that helps please accept solution.

View solution in original post

2 REPLIES 2

avatar
Super Guru

Hi,

If you are looking to set the id value for the first element in the columns array you can use the following spec:

 

[
  {
    "operation": "shift",
    "spec": {
      "columns": {
        "0": {
          "value": "[].@(1,name)"
        }
      }
    }
  }
]

 

If that helps please accept solution.

avatar
Expert Contributor

@SAMSAL Kudos to you.. it worked.. /\