Package io.crate.action.sql.parser

Examples of io.crate.action.sql.parser.SQLXContentSourceParser


     */
    protected String restSQLExecute(String source, boolean includeTypes) throws IOException {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.generator().usePrettyPrint();
        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        parser.parseSource(new BytesArray(source));

        SQLBaseResponse sqlResponse;
        Object[][] bulkArgs = context.bulkArgs();
        if (bulkArgs != null && bulkArgs.length > 0) {
            SQLBulkRequestBuilder requestBuilder = new SQLBulkRequestBuilder(client());
View Full Code Here


                    new SQLActionException("missing request body", 4000, RestStatus.BAD_REQUEST, null)));
            return;
        }

        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        try {
            parser.parseSource(request.content());
        } catch (SQLParseException e) {
            StringWriter stackTrace = new StringWriter();
            e.printStackTrace(new PrintWriter(stackTrace));
            channel.sendResponse(new CrateThrowableRestResponse(channel,
                    new SQLActionException(e.getMessage(), 4000, RestStatus.BAD_REQUEST, stackTrace.toString())));
View Full Code Here

    }

    @Test
    public void testArgsParser() throws Exception {
        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        BytesArray source = new BytesArray("{\n" +
            "    \"stmt\": \"select * from locations where id = $2\",\n" +
            "    \"args\": [[\"1\", \"2\"], \"1\", 1, 2, 2.0, 99999999999999999999999999999999]\n" +
            "}\n");
        parser.parseSource(source);

        ObjectMapper mapper = new ObjectMapper();
        assertEquals(
            "[[\"1\",\"2\"],\"1\",1,2,2.0,99999999999999999999999999999999]",
            mapper.writeValueAsString(context.args()));
View Full Code Here

    @Test
    public void testArgsParserNestedList() throws Exception {

        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        BytesArray source = new BytesArray("{\n" +
            "    \"stmt\": \"select * from locations where id = $2\",\n" +
            "    \"args\": [[\"1\", \"2\", [\"1\"]], \"1\", 1, 2, 2.0, 99999999999999999999999999999999]\n" +
            "}\n");
        parser.parseSource(source);
        ObjectMapper mapper = new ObjectMapper();
        assertEquals("[[\"1\",\"2\",[\"1\"]],\"1\",1,2,2.0,99999999999999999999999999999999]",
            mapper.writeValueAsString(context.args()));
    }
View Full Code Here

    @Test
    public void testArgsParserNestedMap() throws Exception {

        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        BytesArray source = new BytesArray("{\n" +
            "    \"stmt\": \"select * from locations where id = $2\",\n" +
            "    \"args\": [{\"1\": \"2\"}, 1]\n" +
            "}\n");
        parser.parseSource(source);
        ObjectMapper mapper = new ObjectMapper();
        assertEquals("[{\"1\":\"2\"},1]", mapper.writeValueAsString(context.args()));
    }
View Full Code Here

    @Test
    public void testArgsParserVeryNestedMap() throws Exception {

        SQLXContentSourceContext context = new SQLXContentSourceContext();
        SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
        BytesArray source = new BytesArray("{\n" +
            "    \"stmt\": \"select * from locations\",\n" +
            "    \"args\": [{\"1\": {\"2\": {\"3\": 3}}}, [{\"1\": {\"2\": [2, 2]}}]]\n" +
            "}\n");
        parser.parseSource(source);
        ObjectMapper mapper = new ObjectMapper();
        assertEquals("[{\"1\":{\"2\":{\"3\":3}}},[{\"1\":{\"2\":[2,2]}}]]",
            mapper.writeValueAsString(context.args()));
    }
View Full Code Here

TOP

Related Classes of io.crate.action.sql.parser.SQLXContentSourceParser

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.