You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by TearsRed <xi...@live.com> on 2015/05/31 15:00:38 UTC

SubQuery in MetaModel

I don't know if it's politic to send you email, but there is no Issue panel in MetaModel's page on Github.
I've searched http://wiki.apache.org/metamodel/ with keyword "subquery", but there is no result.译
I used to think if org.apache.metamodel.query.Query implements org.apache.metamodel.schema.Table  so I can do it like dataContext.query().from(query), but it doesn't. 
So I ask you how to do SubQuery in MetaModel.

In fact, I think the api of MetaModel can do a big change, like this:
TableLike = dataContext.query().from(TableLike... tables)
TableLike = dataContext.query().from(TableLike... tables).select(ColumnLike... columns)
Filter = ColumnLike.operator(value)dataContext.query().from(TableLike... tables).select(ColumnLike... columns).where(Filter... filters).groupBy(ColumnLike... columns)
There are 3 main interfaces: TableLike , ColumnLike , Filter.
query, table, view are all TableLike;column in a query, column in a table are all ColumnLike;filter is generated by ColumnLike...
By the way, if the Column Type can be represent by the class of Column, things may be better.Maybe we can't make Column a generic class like Column<Integer>, because we can't use it like Column<Person>(wait, wait, wait, maybe we can if Person is just a java bean.... WOW, it seems that TableLike is in fact a subclass of ColumnLike).... So we can have some simple column class like IntegerColumn, StringColumn, DateColumn.....
AgainI don't know if it's politic to send you email. If it's not, ignore the email.  If it doesn't matter, will you reply me? 		 	   		  

Re: SubQuery in MetaModel

Posted by Kasper Sørensen <i....@gmail.com>.
Hi there,

Not sure what you mean with "politic", but certainly asking questions like
this is ALWAYS fine :-)

Actually you can select from a subquery, you just have to wrap the subquery
in a new FromItem(subQuery). Then select from that FromItem.

Regarding typed columns, I am happy to see some initiatives there. Main
advantage from my standpoint is that then we could have also typed return
values when getting stuff out of datasets. Example/suggestion code:

DataSet ds = ...
> TypedColumn<String> c = ...
> String s = ds.getValue(c);


Normally I would need to do a cast (to the 's' variable) there ...

The other thing you mention is having a Person type or so. I would not
agree that table could ever be a specialization of column. But that is in
my opinion then more about having a typed/mapped DataSet.
Example/suggestion code:

DataSet ds = ...
> MappedDataSet<Person> mds = new MappedDataSetImpl<Person>(ds,
> personMapper);
> while (mds.next()) {
>   Person person = mds.getObject();
>   doSomething(person);
> }


That would be pretty cool for many purposes I guess!

2015-05-31 15:00 GMT+02:00 TearsRed <xi...@live.com>:

> I don't know if it's politic to send you email, but there is no Issue
> panel in MetaModel's page on Github.
> I've searched http://wiki.apache.org/metamodel/ with keyword "subquery",
> but there is no result.译
> I used to think if org.apache.metamodel.query.Query implements
> org.apache.metamodel.schema.Table  so I can do it like
> dataContext.query().from(query), but it doesn't.
> So I ask you how to do SubQuery in MetaModel.
>
> In fact, I think the api of MetaModel can do a big change, like this:
> TableLike = dataContext.query().from(TableLike... tables)
> TableLike = dataContext.query().from(TableLike...
> tables).select(ColumnLike... columns)
> Filter = ColumnLike.operator(value)dataContext.query().from(TableLike...
> tables).select(ColumnLike... columns).where(Filter...
> filters).groupBy(ColumnLike... columns)
> There are 3 main interfaces: TableLike , ColumnLike , Filter.
> query, table, view are all TableLike;column in a query, column in a table
> are all ColumnLike;filter is generated by ColumnLike...
> By the way, if the Column Type can be represent by the class of Column,
> things may be better.Maybe we can't make Column a generic class like
> Column<Integer>, because we can't use it like Column<Person>(wait, wait,
> wait, maybe we can if Person is just a java bean.... WOW, it seems that
> TableLike is in fact a subclass of ColumnLike).... So we can have some
> simple column class like IntegerColumn, StringColumn, DateColumn.....
> AgainI don't know if it's politic to send you email. If it's not, ignore
> the email.  If it doesn't matter, will you reply me?
>