Hi Anup,
The composite rowkey you're creating is the one that ksqlDB will automatically create if you GROUP BY multiple expressions. You can simplify your query to become the following:
CREATE TABLE TEST_TABLE WITH (KAFKA_TOPIC='TEST_TABLE', PARTITIONS=10, REPLICAS=2) AS
SELECT
col1,
col2,
col3,
AS_VALUE(col1) as col1_val,
AS_VALUE(col2) as col2_val,
AS_VALUE(col3) as col3_val,
latest_by_offset(CAST(dep AS STRING)) as latest_dep
FROM
sample_stream
GROUP BY col1, col2, col3
EMIT CHANGES;
This will result in a single key column that is "CAST(col1 AS STRING) + '|+|' + CAST(col2 AS STRING) + '|+|' + CAST(col3 AS STRING)" as desired. The column will be named KSQL_COL_0.
If you want the copies of col1, col2, and col3 in the value to be type STRING specifically, you can cast them if they are not already strings.
Best,
Victoria
P.S. This behavior is changing in ksqlDB 0.15, which will introduce native support for multiple key columns. With ksqlDB 0.15, you'll no longer need to concatenate the different columns together :)