You can translate the question and the replies:

How to split then flatten with row number (index of the item flattened)?

Hi, I have a question regarding how to perform an operation in Denodo. I have data in a base view (on a Snowflake data source) that looks like: | Order_number | Icd10_codes | Icd9_codes | | -------- | -------- | -------- | | 1001 | 100.1,101.2 | | | 1002 | | 98.4Z | I want to create a view with the resulting output being: | Order_number | Row_num | Icd_code | | 1001 | 1 | 100.1 | | 1001 | 2 | 101.2 | | 1002 | 1 | 98.4Z | So with the original icd10_codes and icd9_codes strings split on the ',' character then flattened and the item number of the split string for each order_number as row_num. So far what I have done is create two views. View1 splits and unions icd10_codes and icd9_codes: Select order_number, split(',',Icd10_code) as icd UNION Select order_number, split(',',Icd9_code) as icd The second view (view2) flattens the output of this view: Select Order_number, row_number() OVER(PARTITION BY Order_number ORDER BY Order_number) as row_num, <- this does not work String as Icd_code FROM FLATTEN view1 AS v ( v.icd) It all works except for the row_number, as that gives me a resulting message of "Finished with error: Error executing view: Function row_number is not executable". I am guessing this is because since this view is based on another derived view, it won't delegate row_number() down to Snowflake. I checked and row_number() is one of the analytic functions delegated in the Snowflake data source. How would I achieve my desired output with a row_number for each row per order_number?
user
09-05-2023 16:17:39 -0400
code

1 Answer

Hi, It is possible to this by utilizing the Data Movement Optimization. The reason it does not work with your VQL is that the ROW_NUMBER() function is an analytic function (window function). Virtual DataPort can delegate these functions to a database, but cannot execute them. Therefore, if a query uses one of these functions and it cannot be delegated to a database, the query will fail. In your Code you would be applying the ROW_NUMBER() function on a flattend view. The flatten operation is applied outside of the database in Denodo. To use the ROW_NUMBER() function together with a flattened view, you need to move the flattened view to the underlying database, where it is then possible to apply the ROW_NUMBER() function. I suggest to you to create the flattened view in Denodo first. The final query to get your expected results would then look something like this: SELECT *, row_number() OVER(PARTITION BY Order_number ORDER BY Order_number) as row_num FROM <flattened_view> CONTEXT(DATAMOVEMENTPLAN = <flattened_view> : JDBC <denodo_data_base>.<your_snowflake_datasource_name>); You can find more information about this workaround in the [Analytic Functions](https://community.denodo.com/docs/html/browse/8.0/en/vdp/vql/functions/analytic_functions/analytic_functions#workaround-to-execute-analytic-functions/) sections of the Virtual DataPort VQL Guide. It may also be helpful to take a look at the [Data Movement](https://community.denodo.com/docs/html/browse/8.0/en/vdp/administration/optimizing_queries/data_movement/data_movement) section of the Virtual DataPort Administration Guide. Hope this helps!
Denodo Team
10-05-2023 06:09:48 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here