Search in sources :

Example 1 with TableModel

use of io.questdb.cairo.TableModel in project questdb by bluestreak01.

the class KeyedAggregationTest method testCountAggregations.

@Test
public void testCountAggregations() throws Exception {
    try (TableModel tt1 = new TableModel(configuration, "tt1", PartitionBy.NONE)) {
        tt1.col("tts", ColumnType.LONG);
        CairoTestUtils.createTable(tt1);
    }
    String expected = "max\tcount\n" + "NaN:LONG\t0:LONG\n";
    String sql = "select max(tts), count() from tt1";
    assertSqlWithTypes(sql, expected);
    assertSqlWithTypes(sql + " where now() > '1000-01-01'", expected);
    expected = "count\n" + "0:LONG\n";
    sql = "select count() from tt1";
    assertSqlWithTypes(sql, expected);
    assertSqlWithTypes(sql + " where now() > '1000-01-01'", expected);
}
Also used : TableModel(io.questdb.cairo.TableModel) Test(org.junit.Test)

Example 2 with TableModel

use of io.questdb.cairo.TableModel in project questdb by bluestreak01.

the class KeyedAggregationTest method testAggregations.

private void testAggregations(String[] aggregateFunctions, TypeVal[] aggregateColTypes) throws SqlException {
    StringBuilder sql = new StringBuilder();
    sql.append("select ");
    StringBuilder resultHeader = new StringBuilder();
    StringBuilder resultData = new StringBuilder();
    try (TableModel tt1 = new TableModel(configuration, "tt1", PartitionBy.NONE)) {
        for (TypeVal colType : aggregateColTypes) {
            tt1.col(colType.colName, colType.columnType);
        }
        CairoTestUtils.createTable(tt1);
    }
    for (TypeVal colType : aggregateColTypes) {
        for (String func : aggregateFunctions) {
            sql.setLength(7);
            resultHeader.setLength(0);
            resultData.setLength(0);
            String typeStr = getColumnName(colType.columnType);
            sql.append(func).append("(").append(colType.funcArg).append(") ").append(func).append(typeStr);
            sql.append(" from tt1");
            resultHeader.append(func).append(typeStr);
            resultData.append(colType.emtpyValue);
            String expected = resultHeader.append("\n").append(resultData).append("\n").toString();
            assertSqlWithTypes(sql.toString(), expected);
            // Force to go to not-vector execution
            assertSqlWithTypes(sql + " where now() > '1000-01-01'", expected);
        }
    }
}
Also used : TableModel(io.questdb.cairo.TableModel)

Example 3 with TableModel

use of io.questdb.cairo.TableModel in project questdb by bluestreak01.

the class KeyedAggregationTest method testCountCaseInsensitive.

@Test
public void testCountCaseInsensitive() throws Exception {
    try (TableModel tt1 = new TableModel(configuration, "tt1", PartitionBy.DAY)) {
        tt1.col("tts", ColumnType.LONG).timestamp("ts").col("ID", ColumnType.LONG);
        createPopulateTable(tt1, 100, "2020-01-01", 2);
    }
    String expected = "ts\tcount\n" + "2020-01-01T00:28:47.990000Z:TIMESTAMP\t1:LONG\n" + "2020-01-01T00:57:35.980000Z:TIMESTAMP\t1:LONG\n";
    String sql = "select ts, count() from tt1 WHERE id > 0 LIMIT 2";
    assertSqlWithTypes(sql, expected);
}
Also used : TableModel(io.questdb.cairo.TableModel) Test(org.junit.Test)

Example 4 with TableModel

use of io.questdb.cairo.TableModel in project questdb by bluestreak01.

the class FloatGroupByFunctionsTest method testSampleBy.

@Test
public void testSampleBy() throws SqlException, NumericException {
    sqlExecutionContext.setRandom(new Rnd());
    try (TableModel tm = new TableModel(configuration, "tab", PartitionBy.DAY)) {
        tm.timestamp("ts").col("ch", ColumnType.FLOAT);
        createPopulateTable(tm, 100, "2020-01-01", 2);
    }
    assertSql("select ts, min(ch), max(ch), first(ch), last(ch), count() from tab sample by d", "ts\tmin\tmax\tfirst\tlast\tcount\n" + "2020-01-01T00:28:47.990000Z\t0.0010\t0.0510\t0.0010\t0.0510\t51\n" + "2020-01-02T00:28:47.990000Z\t0.0520\t0.1000\t0.0520\t0.1000\t49\n");
}
Also used : Rnd(io.questdb.std.Rnd) TableModel(io.questdb.cairo.TableModel) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 5 with TableModel

use of io.questdb.cairo.TableModel in project questdb by bluestreak01.

the class TableMetadataCursorFactoryTest method testMetadataQueryWithWhereAndSelect.

@Test
public void testMetadataQueryWithWhereAndSelect() throws Exception {
    try (TableModel tm1 = new TableModel(configuration, "table1", PartitionBy.DAY)) {
        tm1.col("abc", ColumnType.STRING);
        tm1.timestamp("ts1");
        createPopulateTable(tm1, 0, "2020-01-01", 0);
    }
    try (TableModel tm1 = new TableModel(configuration, "table2", PartitionBy.NONE)) {
        tm1.timestamp("ts2");
        createPopulateTable(tm1, 0, "2020-01-01", 0);
    }
    assertSql("select designatedTimestamp from tables where name = 'table1'", "designatedTimestamp\n" + "ts1\n");
}
Also used : TableModel(io.questdb.cairo.TableModel) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Aggregations

TableModel (io.questdb.cairo.TableModel)17 Test (org.junit.Test)14 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)8 Path (io.questdb.std.str.Path)3 FilesFacade (io.questdb.std.FilesFacade)1 Rnd (io.questdb.std.Rnd)1