Rename fieldnames based on an import configuration table

I have cassandra database with two tables "products" and "fields".
The product table consists of the following fields: "ID", "1:Value", "2:Value", .. "99:Value"
Example:
"ID", "1:Value", "2:Value", "3:Value"
1, Test, 23, TestA
2, Test-2, 24, TestA-2

The fields table consists of "fieldID", "fieldname"
Example:
1, "Method"
2, "Number"
3, "Alternative"

I now want to export the "products" table into a csv file - but renaming the fields based on the definition in table "fields" (also the names should be changed).
The export should look like
"ID", "Method", "Number", "Alternative"
1, Test, 23, TestA
2, Test-2, 24, TestA-2

What is the right way to do so?
Using jdbc_static?
Or ruby-code?
The problem is that the number of fields is flexible... And I do not know how to get field names as another "input" (apart from jdbc_static or jdb_streaming - but both of them tend rather to be used as "foreign key - values" instead of renaming of fieldnames)

Thanks so much!
Pascal