You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by "Kasper Sørensen (JIRA)" <ji...@apache.org> on 2015/09/07 20:38:45 UTC

[jira] [Closed] (METAMODEL-186) CSV filters in where clause always apply to first file column

     [ https://issues.apache.org/jira/browse/METAMODEL-186?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kasper Sørensen closed METAMODEL-186.
-------------------------------------
    Resolution: Not A Problem
      Assignee: Kasper Sørensen

Actually the culprit here is that you instantiate a new column (MutableColumn) instead of resolving the column that is already discoverable. When you create a new one there is essentially a metadata disconnect and it's an implementation detail how the underlying engine will then select what to do.

Proper approaches would be:

 * First get the column via the dataContext, for instance DataContext.getColumnByQualifiedLabel("age") - and then use this as the Column in your FilterItem.

 * Use the query builder API: DataContext.query().from(...).select(...).where("age").eq("foo");

 * Use the parsed .where(String...) method: Query.where("age = 'foo'");

> CSV filters in where clause always apply to first file column
> -------------------------------------------------------------
>
>                 Key: METAMODEL-186
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-186
>             Project: Apache MetaModel
>          Issue Type: Bug
>    Affects Versions: 4.3.2
>            Reporter: Rafael Garrote
>            Assignee: Kasper Sørensen
>
> The filters added into where clause always apply to first file column.
> I made a test to reproduce the bug: 
>   "CSV Metamodel" should {
>     "Filter test" in new Scope {
>       val context = DataContextFactory.createCsvDataContext(new File("test/resources/csv_people.csv"), ',', DataContextFactory.DEFAULT_CSV_QUOTE_CHAR)
>       val queryParser = new QueryParser(context, "SELECT * FROM csv_people.csv")
>       val filter = new FilterItem(new SelectItem(new MutableColumn("age", ColumnType.STRING)), OperatorType.GREATER_THAN, 8)
>       val query = queryParser.parse()
>       val result = context.executeQuery(query.where(filter))
>       result.toRows.size() mustEqual 9
>     }
>   }
> It must return 9 rows but returns 2 because the filter is applying to the firs column id.
> If replace filter object by this other one: 
> val filter = new FilterItem(new SelectItem(new MutableColumn("id", ColumnType.STRING)), OperatorType.GREATER_THAN, 8)
> The result is the same.
> I have used the csv_people.csv included in test resources for csv module.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)