[
https://issues.apache.org/jira/browse/NIFI-14162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17947940#comment-17947940
]
Daniel Stieglitz edited comment on NIFI-14162 at 4/28/25 9:01 PM:
------------------------------------------------------------------
On my box I added this unit test to TestCalciteDatabase based on the original
issue
{code:java}
@Test
void
testAllStringSingleRowTableWithSelectQueryNotUsingColumnsAsDefinedOrder()
throws Exception{
final List<Object[]> rows = new ArrayList<>();
rows.add(new Object[] {"12345", "10101", "Credit Card", "Porduct
Credit", "RO"});
final String query = "SELECT ArticleCode, ArticleName, ProductCode,
ProductName, Country FROM CANNED_DATA";
try (final CalciteDatabase database = createAllStringDatabase(rows);
final PreparedStatement stmt =
database.getConnection().prepareStatement(query);
final ResultSet resultSet = stmt.executeQuery()) {
assertTrue(resultSet.next());
List<String> actualRow = new ArrayList<>();
for(int index = 1; index <= 5; index++) {
actualRow.add(resultSet.getString(index));
}
List<String> expectedRow = List.of("12345", "Credit Card", "10101",
"Porduct Credit", "RO");
assertEquals(expectedRow, actualRow);
}
}
private CalciteDatabase createAllStringDatabase(List<Object[]> rows) throws
SQLException {
final CalciteDatabase database = new CalciteDatabase();
final NiFiTableSchema tableSchema = new NiFiTableSchema(List.of(
new ColumnSchema("ArticleCode", String.class, false),
new ColumnSchema("ProductCode", String.class, false),
new ColumnSchema("ArticleName", String.class, false),
new ColumnSchema("ProductName", String.class, false),
new ColumnSchema("Country", String.class, false)
));
final ListDataSource arrayListDataSource = new
ListDataSource(tableSchema, rows);
final NiFiTable table = new NiFiTable("CANNED_DATA",
arrayListDataSource, mock(ComponentLog.class));
database.addTable(table);
return database;
}
{code}
which fails with message
{code:java}
Expected :[12345, Credit Card, 10101, Porduct Credit, RO]
Actual :[12345, 10101, Credit Card, Porduct Credit, RO]{code}
was (Author: JIRAUSER294662):
On my box I added this unit test to TestCalciteDatabase based on the original
issue which fails
{code:java}
@Test
void
testAllStringSingleRowTableWithSelectQueryNotUsingColumnsAsDefinedOrder()
throws Exception{
final List<Object[]> rows = new ArrayList<>();
rows.add(new Object[] {"12345", "10101", "Credit Card", "Porduct
Credit", "RO"});
final String query = "SELECT ArticleCode, ArticleName, ProductCode,
ProductName, Country FROM CANNED_DATA";
try (final CalciteDatabase database = createAllStringDatabase(rows);
final PreparedStatement stmt =
database.getConnection().prepareStatement(query);
final ResultSet resultSet = stmt.executeQuery()) {
assertTrue(resultSet.next());
List<String> actualRow = new ArrayList<>();
for(int index = 1; index <= 5; index++) {
actualRow.add(resultSet.getString(index));
}
List<String> expectedRow = List.of("12345", "Credit Card", "10101",
"Porduct Credit", "RO");
assertEquals(expectedRow, actualRow);
}
}
private CalciteDatabase createAllStringDatabase(List<Object[]> rows) throws
SQLException {
final CalciteDatabase database = new CalciteDatabase();
final NiFiTableSchema tableSchema = new NiFiTableSchema(List.of(
new ColumnSchema("ArticleCode", String.class, false),
new ColumnSchema("ProductCode", String.class, false),
new ColumnSchema("ArticleName", String.class, false),
new ColumnSchema("ProductName", String.class, false),
new ColumnSchema("Country", String.class, false)
));
final ListDataSource arrayListDataSource = new
ListDataSource(tableSchema, rows);
final NiFiTable table = new NiFiTable("CANNED_DATA",
arrayListDataSource, mock(ComponentLog.class));
database.addTable(table);
return database;
}
{code}
> QueryRecord not following column order
> --------------------------------------
>
> Key: NIFI-14162
> URL: https://issues.apache.org/jira/browse/NIFI-14162
> Project: Apache NiFi
> Issue Type: Bug
> Affects Versions: 2.0.0
> Reporter: alexduta
> Assignee: Daniel Stieglitz
> Priority: Minor
>
> It seems that, in Nifi, in the QueryRecord processor, if you define some
> columns you select from flowfile, it is following the order, but is taking
> the values in their order from the original flowfile.
> As an example:
> Original Json flowfile:
> {code:java}
> // [{
> "ArticleCode" : "12345",
> "ProductCode" : "10101",
> "ArticleName" : "Credit Card",
> "ProductName" : "Porduct Credit",
> "Country" : "RO"
> }] {code}
>
>
> Query:
>
> {code:java}
> // select ArticleCode,ArticleName,ProductCode,ProductName,Country from
> FLOWFILE
> {code}
>
>
> Returning file:
>
> {code:java}
> // [{
> "ArticleCode" : "12345",
> "ArticleName" : "10101",
> "ProductCode" : "Credit Card",
> "ProductName" : "Porduct Credit",
> "Country" : "RO"
> }] {code}
>
> So, it is somehow just adding the name of the columns, but is not changing
> the values.
>
> Otherwise, if one of the records in the flowfile has the correct order in it,
> the others will follow the correct rule:
> Original file:
> {code:java}
> // [{
> "ArticleCode" : "12345",
> "ArticleName" : "Credit Card",
> "ProductCode" : "10101",
> "ProductName" : "Porduct Credit",
> "Country" : "RO"
> },
> {
> "ArticleCode" : "12346",
> "ProductCode" : "10102",
> "ArticleName" : "Business Card",
> "ProductName" : "Society Credit",
> "Country" : "RO"
> }] {code}
> or
> {code:java}
> // [
> {
> "ArticleCode" : "12345",
> "ProductCode" : "10101",
> "ArticleName" : "Credit Card",
> "ProductName" : "Porduct Credit",
> "Country" : "RO"
> },{
> "ArticleCode" : "12346",
> "ArticleName" : "Business Card",
> "ProductCode" : "10102",
> "ProductName" : "Society Credit",
> "Country" : "RO"
> }] {code}
> Returning file:
> {code:java}
> // [{
> "ArticleCode" : "12345",
> "ArticleName" : "Credit Card",
> "ProductCode" : "10101",
> "ProductName" : "Porduct Credit",
> "Country" : "RO"
> },
> {
> "ArticleCode" : "12346",
> "ArticleName" : "Business Card",
> "ProductCode" : "10102",
> "ProductName" : "Society Credit",
> "Country" : "RO"
> }] {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)