How to control the case of identifiers¶
Context¶
You have identifiers, like row names, that will be used outside of ksqlDB. You want to control the exact casing (capitalization) of how they are represented to make them consumable by downstream programs. Because ksqlDB uppercases all identifiers by default, you need to use backticks to preserve the desired casing.
In action¶
1 2 3 4 5 6 7 8 9 |
|
Backticks¶
Begin by telling ksqlDB to start all queries from the earliest point in each topic.
1 |
|
Declare a new stream named s2
. In this example, you override
ksqlDB's default behavior to uppercase all identifiers. Use backticks
to control the casing of the stream name and column names. To contrast
this behavior, qux
is declared without backticks to demonstrate
the default behavior of uppercasing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Insert some rows into s2
. Notice how you need to use backticks each
time to reference a field that doesn't have the default casing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Issue a push query to select the rows. The relevant identifiers are
again surrounded with backticks. Notice that since qux
wasn't
declared with backticks, it can be referred to with any casing. ksqlDB
will find the matching identifer by uppercasing it automatically.
1 2 3 4 5 6 7 8 9 |
|
Your output should resemble the following. Notice the casing of the headers that ksqlDB prints:
1 2 3 4 5 6 |
|
User-defined functions¶
Another area where casing is important is user-defined functions (UDFs) that work with struct parameters. This is the case whenever you use a UDF that either receives an incoming struct or returns a custom struct. Any references to struct fields must exactly match the casing ksqlDB expects. ksqlDB will reject any UDF invocations that do not match it.
Here is a quick example of using backticks in a UDF that returns a custom struct. The first two fields override the default behavior. The last uses the default casing. That means that when you work with the data returned from the UDF in ksqlDB, all select statements must use this exact casing (see the example above). For more information on working with structs in UDFs, see the struct section of the how to create a user-defined function guide.
1 2 3 4 5 |
|