Need help with UDTF user function

Hallo! Im newbie here) I creating analytics patform with kafka and clickhouse. Input data have this format:

 "orderData": {
      "shopId": 3001,
      "number": "362495",
      "id": "35c57d7f-a668-4ae6-abce-ebf15cdfb0f8",
      "carrier": 500,
      "deliveryCost": 0,
      "paymentMode": "9",
      "email": "nastya_savkina@mail.ru",
      "zipCode": 125212,
      "source": "webSite",
      "items": [
        {
          "ean": "6438429628552",
          "quantity": 1,
          "price": 8549
        }
      ]
    },

I created stream it worked fine, but im want put items to plain table in clickhouse, like this:

Ean|Quantity|Price
"6438429628552"|1|8549

So, i trying to create UDTF user function:

@UdtfDescription(name="ORDERS_ITEMS_TABLE", description="Convert array of order items to table")
public class OrderItemsTable {
	public static final String INPUT_STRUCT_DESCRIPTOR = "STRUCT<EAN STRING, QUANTITY BIGINT,  PRICE DOUBLE>";
	
	@Udtf
	public <T> List<Object> orderItemsTable(@UdfParameter(schema = "ARRAY<" + INPUT_STRUCT_DESCRIPTOR + ">") final List<Struct> orderItems) {
		List<Object> outputTable = new ArrayList<>();
		
		for(int i = 0; i < orderItems.size(); i++) {
			Struct item = orderItems.get(i);
			outputTable.add(item.get("ean"));
			outputTable.add(item.get("price"));
			outputTable.add(item.get("quantity"));
		}
		
		return outputTable;
	}
}

And got this error:

"SELECT ORDERS_ITEMS_TABLE(ORDER_ITEMS) FROM orders_json_stream EMIT CHANGES;"
I got a error:
Function 'ORDERS_ITEMS_TABLE' does not accept parameters (ARRAY<STRUCT<EAN STRING, QUANTITY BIGINT, PRICE DOUBLE>>).

Thanks for your time. Would be glad for any help. Regards.

Veeresh says:

“I think array must be declared in square brackets, please do check it out once with the name of the struct defined along with that” on Slack

This topic was automatically closed after 30 days. New replies are no longer allowed.