Package io.crate.action.sql

Examples of io.crate.action.sql.SQLResponse


                }}
        });
        refresh();
        waitNoPendingTasksOnAll();

        SQLResponse response = execute("select id, new_col from t1 where id=0");
        @SuppressWarnings("unchecked")
        Map<String, Object> mapped = (Map<String, Object>)response.rows()[0][1];
        assertEquals(0, mapped.get("a_date"));
        assertEquals(127, mapped.get("an_int"));
        assertEquals(0x7fffffffffffffffL, mapped.get("a_long"));
        assertEquals(true, mapped.get("a_boolean"));
    }
View Full Code Here


            put("another_new_col", "1970-01-01T00:00:00");
        }};
        execute("insert into test12 (object_field) values (?)",
                new Object[]{objectContent});
        refresh();
        SQLResponse response = execute("select object_field from test12");
        assertEquals(1, response.rowCount());
        @SuppressWarnings("unchecked")
        Map<String, Object> selectedObject = (Map<String, Object>)response.rows()[0][0];

        assertThat((String)selectedObject.get("new_col"), is("a string"));
        assertEquals(0, selectedObject.get("another_new_col"));
    }
View Full Code Here

            put("another_new_col", "1970-01-01T00:00:00");
        }};
        execute("insert into test12 (no_dynamic_field) values (?)",
                new Object[]{notDynamicContent});
        refresh();
        SQLResponse response = execute("select no_dynamic_field from test12");
        assertEquals(1, response.rowCount());
        @SuppressWarnings("unchecked")
        Map<String, Object> selectedNoDynamic = (Map<String, Object>)response.rows()[0][0];
        // no mapping applied
        assertThat((String)selectedNoDynamic.get("new_col"), is("a string"));
        assertThat((String)selectedNoDynamic.get("another_new_col"), is("1970-01-01T00:00:00"));
    }
View Full Code Here

        client2.execute(SQLAction.INSTANCE, new SQLRequest(
            "insert into t1 (id, string_field, timestamp_field, byte_field) values (?, ?, ?, ?)",
            new Object[]{2, "Without", "1970-01-01T01:00:00", Byte.MIN_VALUE})).actionGet();
        refresh();
        SQLResponse response = execute("select id, string_field, timestamp_field, byte_field from t1 order by id");

        assertEquals(1, response.rows()[0][0]);
        assertEquals("With", response.rows()[0][1]);
        assertEquals(0, response.rows()[0][2]);
        assertEquals(127, response.rows()[0][3]);

        assertEquals(2, response.rows()[1][0]);
        assertEquals("Without", response.rows()[1][1]);
        assertEquals(3600000, response.rows()[1][2]);
        assertEquals(-128, response.rows()[1][3]);
    }
View Full Code Here

                        );
                    }}
        });
        refresh();

        SQLResponse response = execute("select object_field, strict_field, no_dynamic_field from test12");
        assertEquals(1, response.rowCount());
        assertThat(response.rows()[0][0], instanceOf(Map.class));
        @SuppressWarnings("unchecked")
        Map<String, Object> objectMap = (Map<String, Object>)response.rows()[0][0];
        assertEquals(1384819200000L, objectMap.get("created"));
        assertEquals(127, objectMap.get("size"));

        assertThat(response.rows()[0][1], instanceOf(Map.class));
        @SuppressWarnings("unchecked")
        Map<String, Object> strictMap = (Map<String, Object>)response.rows()[0][1];
        assertEquals("/dev/null", strictMap.get("path"));
        assertEquals(0, strictMap.get("created"));

        assertThat(response.rows()[0][2], instanceOf(Map.class));
        @SuppressWarnings("unchecked")
        Map<String, Object> noDynamicMap = (Map<String, Object>)response.rows()[0][2];
        assertEquals("/etc/shadow", noDynamicMap.get("path"));
        assertEquals(
                new HashMap<String, Object>(){{ put("field", 1384790145289L); }},
                noDynamicMap.get("dynamic_again")
        );

        response = execute("select object_field['created'], object_field['size'], " +
                "no_dynamic_field['dynamic_again']['field'] from test12");
        assertEquals(1384819200000L, response.rows()[0][0]);
        assertEquals(127, response.rows()[0][1]);
        assertEquals(1384790145289L, response.rows()[0][2]);
    }
View Full Code Here

                    1.0f, Math.PI, true, "a string", "2013-11-20",
                    new HashMap<String, Object>() {{put("inner", "2013-11-20");}}, "127.0.0.1"
        });
        refresh();

        SQLResponse response = execute("select id, byte_field, short_field, integer_field, long_field," +
                "float_field, double_field, boolean_field, string_field, timestamp_field," +
                "object_field, ip_field from t1 where id=0");
        assertEquals(1, response.rowCount());
        assertEquals(0, response.rows()[0][0]);
        assertEquals(127, response.rows()[0][1]);
        assertEquals(-32768, response.rows()[0][2]);
        assertEquals(0x7fffffff, response.rows()[0][3]);
        assertEquals(0x8000000000000000L, response.rows()[0][4]);
        assertEquals(1.0f, ((Number) response.rows()[0][5]).floatValue(), 0.01f);
        assertEquals(Math.PI, response.rows()[0][6]);
        assertEquals(true, response.rows()[0][7]);
        assertEquals("a string", response.rows()[0][8]);
        assertEquals(1384905600000L, response.rows()[0][9]);
        assertEquals(new HashMap<String, Object>() {{ put("inner", 1384905600000L); }}, response.rows()[0][10]);
        assertEquals("127.0.0.1", response.rows()[0][11]);
    }
View Full Code Here

        assertEquals(response.rows()[0][1], response.rows()[2][1]);
    }

    @Test
    public void testSelectGlobalExpressionGlobalAggregate() throws Exception {
        SQLResponse response = executor.exec("select count(distinct race), sys.cluster.name " +
                "from characters group by sys.cluster.name");
        assertEquals(1, response.rowCount());
        assertArrayEquals(new String[]{"count(DISTINCT race)", "sys.cluster.name"}, response.cols());
        assertEquals(3L, response.rows()[0][0]);
        assertEquals(GLOBAL_CLUSTER.clusterName(), response.rows()[0][1]);
    }
View Full Code Here

        assertEquals(GLOBAL_CLUSTER.clusterName(), response.rows()[0][1]);
    }

    @Test
    public void testSelectGroupByOrderByNullSortingASC() throws Exception {
        SQLResponse response = executor.exec("select age from characters group by age order by age");
        assertEquals(32, response.rows()[0][0]);
        assertEquals(34, response.rows()[1][0]);
        assertEquals(43, response.rows()[2][0]);
        assertEquals(112, response.rows()[3][0]);
        assertEquals(null, response.rows()[4][0]);
    }
View Full Code Here

        assertEquals(null, response.rows()[4][0]);
    }

    @Test
    public void testSelectGroupByOrderByNullSortingDESC() throws Exception {
        SQLResponse response = executor.exec("select age from characters group by age order by age desc");
        assertEquals(null, response.rows()[0][0]);
        assertEquals(112, response.rows()[1][0]);
        assertEquals(43, response.rows()[2][0]);
        assertEquals(34, response.rows()[3][0]);
        assertEquals(32, response.rows()[4][0]);
    }
View Full Code Here

        assertEquals(32, response.rows()[4][0]);
    }

    @Test
    public void testSelectAggregateOnGlobalExpression() throws Exception {
        SQLResponse response = executor.exec("select count(sys.cluster.name) from characters");
        assertEquals(1, response.rowCount());
        assertEquals(7L, response.rows()[0][0]);

        response = executor.exec("select count(distinct sys.cluster.name) from characters");
        assertEquals(1, response.rowCount());
        assertEquals(1L, response.rows()[0][0]);
    }
View Full Code Here

TOP

Related Classes of io.crate.action.sql.SQLResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.