package com.flipkart.foxtrot.sql;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.junit.Test;

public class ParseTest {
    @Test
    public void test() throws Exception {
        //TODO
        /*ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
        {
            String sql = "select abc.xyz, def from europa order by test.name limit 20 offset 5";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            String sql = "select * from europa order by test.name limit 20 offset 5";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            String sql = "select * from europa group by test.name, test.surname";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            //String sql = "select trend(header.configName) from europa";
            //String sql = "select trend(header.configName, 'minutes') from europa";
            String sql = "select trend(header.configName, 'minutes', 'header.timestamp') from europa";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            //String sql = "select statstrend(header.configName) from europa";
            String sql = "select statstrend(header.configName, 'minutes') from europa";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            //String sql = "select statstrend(header.configName) from europa";
            String sql = "select stats(header.configName) from europa";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            //String sql = "select statstrend(header.configName) from europa";
            //String sql = "select histogram() from europa";
            //String sql = "select histogram('hours') from europa";
            String sql = "select histogram('minutes', 'header.timestamp') from europa";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }
        {
            String sql = "select * from europa where a = 'b' and c=2.5 and temporal(e) between 10 and 30 and x > 99 order by test.name limit 20 offset 5";
            QueryTranslator queryTranslator = new QueryTranslator();
            ActionRequest request = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(request));
        }*/


        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
        {
            String sql = "select * from europa where a is null";
            QueryTranslator queryTranslator = new QueryTranslator();
            FqlQuery query = queryTranslator.translate(sql);
            System.out.println(writer.writeValueAsString(query));
        }
    }
}

@@ -196,20 +196,288 @@
 ort 
-org.junit.Te
+com.flipkart.foxtrot.common.query.Query;%0Aimport com.flipkart.foxtrot.common.query.general.MissingFilter;%0Aimport com.flipkart.foxtrot.sql.query.FqlActionQuery;%0Aimport com.google.common.collect.ImmutableList;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayLi
 st;%0A
@@ -4407,16 +4407,18 @@
         
+//
 FqlQuery
@@ -4470,35 +4470,484 @@
         
-System.out.println(
+Query query = new Query();%0A            query.setTable(%22europa%22);%0A            query.setFrom(0);%0A            query.setLimit(10);%0A            query.setSort(null);%0A            ImmutableList filters = ImmutableList.of(new MissingFilter(%22a%22));%0A            query.setFilters(filters);%0A            FqlActionQuery fqlActionQuery = new FqlActionQuery(FqlQueryType.select,query, new ArrayList%3CString%3E());%0A            Assert.assertEquals(writer.writeValueAsString(fqlActionQuery), 
 writer.w
@@ -4969,20 +4969,46 @@
 ng(query
+Translator.translate(sql)
 ));%0A
+%0A
         

Test fixed as per comment