Search in sources :

Example 1 with InsertStatement

use of io.questdb.cairo.sql.InsertStatement in project questdb by bluestreak01.

the class TelemetryTest method testTelemetryConfigUpgrade.

@Test
public void testTelemetryConfigUpgrade() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            compiler.compile("CREATE TABLE " + TelemetryJob.configTableName + " (id long256, enabled boolean)", sqlExecutionContext);
            InsertStatement ist = compiler.compile("INSERT INTO " + TelemetryJob.configTableName + " values(CAST('0x01' AS LONG256), true)", sqlExecutionContext).getInsertStatement();
            InsertMethod im = ist.createMethod(sqlExecutionContext);
            im.execute();
            im.commit();
            im.close();
            ist.close();
            TelemetryJob telemetryJob = new TelemetryJob(engine, null);
            String expectedSql = "column	type	indexed	indexBlockCapacity	symbolCached	symbolCapacity	designated\n" + "id	LONG256	false	0	false	0	false\n" + "enabled	BOOLEAN	false	0	false	0	false\n" + "version	SYMBOL	false	256	true	128	false\n" + "os	SYMBOL	false	256	true	128	false\n" + "package	SYMBOL	false	256	true	128	false\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SHOW COLUMNS FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "id\tversion\n" + "0x01\t\n" + "0x01\tUnknown Version\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT id, version FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) InsertMethod(io.questdb.cairo.sql.InsertMethod) CairoEngine(io.questdb.cairo.CairoEngine) InsertStatement(io.questdb.cairo.sql.InsertStatement) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 2 with InsertStatement

use of io.questdb.cairo.sql.InsertStatement in project questdb by bluestreak01.

the class SecurityTest method testAlterTableDeniedOnNoWriteAccess.

@Test
public void testAlterTableDeniedOnNoWriteAccess() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
        CompiledQuery cq = compiler.compile("insert into balances values (1, 'EUR', 140.6)", sqlExecutionContext);
        InsertStatement insertStatement = cq.getInsertStatement();
        try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
            method.execute();
            method.commit();
        }
        assertQuery("cust_id\tccy\tbalance\n1\tEUR\t140.6\n", "select * from balances", null, true, true);
        try {
            compiler.compile("alter table balances add column newcol int", readOnlyExecutionContext);
            Assert.fail();
        } catch (Exception ex) {
            Assert.assertTrue(ex.toString().contains("permission denied"));
        }
        assertQueryPlain("cust_id\tccy\tbalance\n1\tEUR\t140.6\n", "select * from balances");
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test)

Example 3 with InsertStatement

use of io.questdb.cairo.sql.InsertStatement in project questdb by bluestreak01.

the class SecurityTest method testInsertDeniedOnNoWriteAccess.

@Test
public void testInsertDeniedOnNoWriteAccess() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
        assertQuery("count\n0\n", "select count() from balances", null, false, true);
        CompiledQuery cq = compiler.compile("insert into balances values (1, 'EUR', 140.6)", sqlExecutionContext);
        InsertStatement insertStatement = cq.getInsertStatement();
        try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
            method.execute();
            method.commit();
        }
        assertQuery("count\n1\n", "select count() from balances", null, false, true);
        try {
            cq = compiler.compile("insert into balances values (2, 'ZAR', 140.6)", readOnlyExecutionContext);
            insertStatement = cq.getInsertStatement();
            try (InsertMethod method = insertStatement.createMethod(readOnlyExecutionContext)) {
                method.execute();
                method.commit();
            }
            Assert.fail();
        } catch (Exception ex) {
            Assert.assertTrue(ex.toString().contains("permission denied"));
        }
        assertQuery("count\n1\n", "select count() from balances", null, false, true);
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test)

Example 4 with InsertStatement

use of io.questdb.cairo.sql.InsertStatement in project questdb by bluestreak01.

the class JsonQueryProcessor method executeInsert.

private void executeInsert(JsonQueryProcessorState state, CompiledQuery cc, CharSequence keepAliveHeader) throws PeerDisconnectedException, PeerIsSlowToReadException, SqlException {
    final InsertStatement insertStatement = cc.getInsertStatement();
    try (InsertMethod insertMethod = insertStatement.createMethod(sqlExecutionContext)) {
        insertMethod.execute();
        insertMethod.commit();
    }
    sendConfirmation(state, cc, keepAliveHeader);
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement)

Example 5 with InsertStatement

use of io.questdb.cairo.sql.InsertStatement in project questdb by bluestreak01.

the class ImportIODispatcherTest method testImportMisDetectsTimestampColumn.

private void testImportMisDetectsTimestampColumn(HttpServerConfigurationBuilder serverConfigBuilder, int rowCount) throws Exception {
    new HttpQueryTestBuilder().withTempFolder(temp).withWorkerCount(1).withHttpServerConfigBuilder(serverConfigBuilder).withTelemetry(false).run((engine) -> {
        setupSql(engine);
        compiler.compile("create table trips(" + "timestamp TIMESTAMP," + "str STRING," + "i STRING" + ") timestamp(timestamp)", sqlExecutionContext);
        String request = PostHeader.replace("name=trips", "name=trips&skipLev=true") + Request1DataHeader + generateImportCsv(0, rowCount, "aaaaaaaaaaaaaaaaa,22222222222222222222,33333333333333333") + Request1SchemaPart;
        new SendAndReceiveRequestBuilder().withExpectSendDisconnect(true).execute(request, "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "\r\n" + "12\r\n" + "not a timestamp ''\r\n" + "00\r\n" + "\r\n");
        CompiledQuery compiledQuery = compiler.compile("insert into trips values (" + "'2021-07-20T00:01:00', 'ABC', 'DEF'" + ")", sqlExecutionContext);
        final InsertStatement insertStatement = compiledQuery.getInsertStatement();
        try (InsertMethod insertMethod = insertStatement.createMethod(sqlExecutionContext)) {
            insertMethod.execute();
            insertMethod.commit();
        }
        compiler.close();
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) CompiledQuery(io.questdb.griffin.CompiledQuery) InsertStatement(io.questdb.cairo.sql.InsertStatement)

Aggregations

InsertMethod (io.questdb.cairo.sql.InsertMethod)5 InsertStatement (io.questdb.cairo.sql.InsertStatement)5 Test (org.junit.Test)3 CairoException (io.questdb.cairo.CairoException)2 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)1 CairoEngine (io.questdb.cairo.CairoEngine)1 CompiledQuery (io.questdb.griffin.CompiledQuery)1 SqlCompiler (io.questdb.griffin.SqlCompiler)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1