Hi Flink experts!! I am hoping for some help in tr...
# troubleshooting
z
Hi Flink experts!! I am hoping for some help in trying to understand and fix an issue I am having with a pretty simple flink application. I am writing an application wherein two flink tables are created with two separate kafka source topics, and then i am aliasing each table's columns via a select statement and joining the two tables together with a left outer join. In each kafka-backed table, I am including primary key definitions. However, when I look at the operator for the joining, it is showing noUniqueKey for the join input specs:
leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey]
For this application, I am executing the table creation sql statement for each of the tables, then building a table api pipeline for the joins and transformations. Finally, I am converting the final "Table" object into a datastream and sinking the data it into Iceberg. This join is resulting in very bad performance, due to the lack of use of the defined unique keys ( primary keys ) on the underlying tables. I believe Flink should persist the unique keys constraints when doing this join and I am struggling to understand what may be going wrong here. Thanks in advance for any help, experience or feedback you can provide!!
p
I think since Kafka is a append only source, it would be not sure the defined PKs are unique. Are you aliasing the output only or do you also alias the tables before the joining? Have you tried using temporal joins to help you achieve performance?
z
Hmm. interesting point about the Kafka append-only source, I will do some digging today to see if I can prove that point to be true! We are aliasing the table and the columns before joining. Essentially we have two source operators which are doing a select and calc in the same operator, selecting from each underlying kafka source topic and aliasing the table and its columns. Example would be a table called transactions and an id column in that table end up as "select t$id, ... from transactions as t". These are then joined together and a resulting Table object is generated. Finally, that Table object is converted into a data stream and put into iceberg via a sink. We haven't tried temporal joins, but this is a somewhat strange use case in that the entire history of the topic/table is relevant, not just the messages which are aligned temporally. If a change record comes in for any one of the tables in the join, it should create an output change record through the Flink pipeline. Thanks so much for your response and ideas. Very, very appreciated!
wanted to share, this is what the source/calc operator looks like right now, and a similar one is generated for the other topic:
Copy code
[1]:TableSourceScan(table=[[default_catalog, default_database, txns]], fields=[amount, balance, id, created_at, ...])
+- [2]:Calc(select=[amount AS t$amount, balance AS t$balance, id AS t$id, created_at AS t$created_at, ...], where=[(type = 'ReceivableInvoice')])
Then, the join/calc operator looks like:
Copy code
Join(joinType=[InnerJoin], where=[((td$txn_id = t$id) AND (td$kafka_key_customer = t$kafka_key_customer))], select=[t$amount, t$balance, t$id, t$created_at, td$balance, ...], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
+- [8]:Calc(select=[t$amount, t$balance, t$bank_account_id, t$id, t$created_at, td$balance, ...])
p
I'd suggest you also try to join without aliasing to be sure. and alias only the output
z
I have solved this for the first join of the first two kafka-backed 'tables' in Flink! Turns out we were not including all three columns that are part of the primary key in the join. But now I'm really stumped on how to solve the harder problem I've uncovered. We are building the final 'Table' object that we convert to a DataStream by way of using a config file to outline the kafka-backed Flink tables to pull from and the join configuration for those. We go through this file and join each of these tables based on the config in a loop, and each time we return a new table object. This means that although I can now get both the
leftInputSpec
and
rightInputSpec
to respect the primary key definitions on the initial join of the two kafka tables, the result is essentially a new table that doesn't have any primary key defined. I understand that it wouldn't make sense for the system to assign a PK automatically in this case. What I need help with now is how in the world can I add a PK to that 'Table' object, leveraging the Table API, before I continue and join that Table object to the next kafka table? I've been digging into the documentation, issues, everywhere and I can't figure out how one would accomplish this, or even if it is accomplishable. 😓
🙌 1