Search in sources :

Example 1 with EntryStream

use of one.util.streamex.EntryStream in project be5 by DevelopmentOnTheEdge.

the class FilterApplierTest method testSetFilterApplier.

@Test
public void testSetFilterApplier() {
    AstStart query = SqlQuery.parse("SELECT * FROM games g, city WHERE g.city = city.name");
    Map<ColumnRef, Object> conditions = EntryStream.<String, Object>of("city.country", "UK", "games.yr", 2012).mapKeys(key -> ColumnRef.resolve(query, key)).toCustomMap(LinkedHashMap::new);
    new FilterApplier().setFilter(query, conditions);
    assertEquals("SELECT * FROM games g, city WHERE city.country ='UK' AND g.yr = 2012", new Formatter().format(query, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
    AstStart query2 = SqlQuery.parse("SELECT city.name, g.* FROM city INNER JOIN games g ON (g.city = city.name)");
    new FilterApplier().setFilter(query2, conditions);
    assertEquals("SELECT city.name, g.* FROM city INNER JOIN games g WHERE city.country ='UK' AND g.yr = 2012", new Formatter().format(query2, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
    AstStart query3 = SqlQuery.parse("SELECT * FROM city JOIN games g ON (g.city = city.name) JOIN games gm ON city.country ='UK'");
    new FilterApplier().setFilter(query3, conditions);
    assertEquals("SELECT * FROM city INNER JOIN games g INNER JOIN games gm WHERE city.country ='UK' AND g.yr = 2012", new Formatter().format(query3, new Context(Dbms.POSTGRESQL), new DefaultParserContext()));
}
Also used : Context(com.developmentontheedge.sql.format.Context) FilterApplier(com.developmentontheedge.sql.format.FilterApplier) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) AstStart(com.developmentontheedge.sql.model.AstStart) EntryStream(one.util.streamex.EntryStream) SqlQuery(com.developmentontheedge.sql.model.SqlQuery) LinkedHashMap(java.util.LinkedHashMap) Formatter(com.developmentontheedge.sql.format.Formatter) Map(java.util.Map) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) Assert(org.junit.Assert) ParseException(java.text.ParseException) Collections(java.util.Collections) ColumnRef(com.developmentontheedge.sql.format.ColumnRef) Dbms(com.developmentontheedge.sql.format.Dbms) Context(com.developmentontheedge.sql.format.Context) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) AstStart(com.developmentontheedge.sql.model.AstStart) Formatter(com.developmentontheedge.sql.format.Formatter) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) FilterApplier(com.developmentontheedge.sql.format.FilterApplier) ColumnRef(com.developmentontheedge.sql.format.ColumnRef) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

ColumnRef (com.developmentontheedge.sql.format.ColumnRef)1 Context (com.developmentontheedge.sql.format.Context)1 Dbms (com.developmentontheedge.sql.format.Dbms)1 FilterApplier (com.developmentontheedge.sql.format.FilterApplier)1 Formatter (com.developmentontheedge.sql.format.Formatter)1 AstStart (com.developmentontheedge.sql.model.AstStart)1 DefaultParserContext (com.developmentontheedge.sql.model.DefaultParserContext)1 SqlQuery (com.developmentontheedge.sql.model.SqlQuery)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 EntryStream (one.util.streamex.EntryStream)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1