Exemple #1
0
CUNIT_TEST(DBSuite, _string_literal)
{
    EagleDbInstance *db = EagleInstanceTest(10);
    EagleBoolean success;
    EagleLoggerEvent *error = NULL;

    success = EagleDbInstance_execute(db, "CREATE TABLE mytable2 (col1 int, col2 text);", &error);
    if (EagleFalse == success) {
        CUNIT_FAIL("%s", error->message);
    }
    CUNIT_ASSERT_TRUE(success);

    success = EagleDbInstance_execute(db, "INSERT INTO mytable2 (col1, col2) VALUES (123, 'some '' cool \' text');", &error);
    if (EagleFalse == success) {
        CUNIT_FAIL("%s", error->message);
    }
    CUNIT_ASSERT_TRUE(success);

    // SELECT data back
    EagleDbParser *p = EagleDbParser_ParseWithString("SELECT col1, col2, 'some string' FROM mytable2;");
    CUNIT_ASSERT_FALSE(EagleDbParser_hasError(p));

    EaglePlan *plan = EagleDbSqlSelect_parse((EagleDbSqlSelect*) p->yyparse_ast, db);
    //printf("%s\n", EaglePlan_toString(plan));

    // catch compilation error
    CUNIT_ASSERT_FALSE(EaglePlan_isError(plan));

    // execute
    EagleInstance *eagle = EagleInstance_New(1);
    EagleInstance_addPlan(eagle, plan);
    EagleInstance_run(eagle);

    // validate data
    EaglePage *page1 = EaglePageProvider_nextPage(plan->result[0]);
    EaglePage *page2 = EaglePageProvider_nextPage(plan->result[1]);
    EaglePage *page3 = EaglePageProvider_nextPage(plan->result[2]);

    CUNIT_ASSERT_EQUAL_INT(page1->type, EagleDataTypeInteger);
    CUNIT_ASSERT_EQUAL_INT(page2->type, EagleDataTypeVarchar);
    CUNIT_ASSERT_EQUAL_INT(page3->type, EagleDataTypeVarchar);
    CUNIT_ASSERT_EQUAL_INT(1, page1->count);
    CUNIT_ASSERT_EQUAL_INT(1, page2->count);
    CUNIT_ASSERT_EQUAL_INT(10, page3->count);
    CUNIT_ASSERT_EQUAL_INT(((int*) page1->data)[0], 123);
    CUNIT_ASSERT_EQUAL_STRING(((char**) page2->data)[0], "some ' cool ' text");
    CUNIT_ASSERT_EQUAL_STRING(((char**) page3->data)[0], "some string");

    EaglePage_Delete(page1);
    EaglePage_Delete(page2);
    EaglePage_Delete(page3);

    EagleInstance_Delete(eagle);
    EaglePlan_Delete(plan);

    EagleDbSqlSelect_DeleteRecursive((EagleDbSqlSelect*) p->yyparse_ast);
    EagleDbParser_Delete(p);

    EagleInstanceTest_Cleanup(db);
}
Exemple #2
0
CUNIT_TEST(BenchSuite, distance)
{
    int pageSize = 1000, rows = 1000000, cores = 8;
    EagleDbInstance *db = EagleDbInstance_New(pageSize, cores);
    EagleLoggerEvent *error = NULL;
    EagleBoolean success;
    
    // create table
    success = EagleDbInstance_execute(db, "CREATE TABLE point (id INT, x DOUBLE, y DOUBLE);", &error);
    if(EagleFalse == success) {
        CUNIT_FAIL("%s", error->message);
    }
    
    // add data
    srand(0);
    EagleDbParser *p = _BenchSuite_distance(db, rows);
        
    // execute
    for(int i = 0; i < 10; ++i) {
        EaglePlan *plan = EagleDbSqlSelect_parse((EagleDbSqlSelect*) p->yyparse_ast, db);
        if(EagleTrue == EaglePlan_isError(plan)) {
            CUNIT_FAIL("%s", plan->errorMessage);
        }
        //printf("%s\n", EaglePlan_toString(plan));
        
        EagleInstance *eagle = EagleInstance_New(cores);
        EagleInstance_addPlan(eagle, plan);
        EagleInstance_run(eagle);
        
        // print results
        /*while(EaglePageProvider_pagesRemaining(plan->result[0]) > 0) {
         EaglePage *id = EaglePageProvider_nextPage(plan->result[0]);
         EaglePage *x = EaglePageProvider_nextPage(plan->result[1]);
         EaglePage *y = EaglePageProvider_nextPage(plan->result[2]);
         
         for(int i = 0; i < id->count; ++i) {
         EagleDataTypeFloatType _x = ((EagleDataTypeFloatType*) x->data)[i];
         EagleDataTypeFloatType _y = ((EagleDataTypeFloatType*) y->data)[i];
         
         printf("(id = %d, x = %g, y = %g) -> %g\n", ((EagleDataTypeIntegerType*) id->data)[i], _x, _y,
         sqrt((500.0 - _x) * (500.0 - _x) + (500.0 - _y) * (500.0 - _y)));
         }
         }*/
        
        // check timing
        CUNIT_ASSERT_BENCH_RESULT(plan, cores);
        EaglePlan_Delete(plan);
    }
    
    EagleDbSqlSelect_DeleteRecursive((EagleDbSqlSelect*) p->yyparse_ast);
    EagleDbParser_Delete(p);
    EagleDbInstance_Delete(db);
}
Exemple #3
0
CUNIT_TEST(DBSuite, EagleDbInformationSchema_tables)
{
    int cores = 1;
    EagleDbInstance *db = EagleDbInstance_New(10, cores);

    /* parse sql */
    EagleDbParser *p = EagleDbParser_ParseWithString("select table_schema, table_name from information_schema_tables;");
    if (EagleTrue == EagleDbParser_hasError(p)) {
        CUNIT_FAIL("%s", EagleDbParser_lastError(p));
    }
    CUNIT_ASSERT_FALSE(EagleDbParser_hasError(p));

    EaglePlan *plan = EagleDbSqlSelect_parse((EagleDbSqlSelect*) p->yyparse_ast, db);
    if (EagleTrue == EaglePlan_isError(plan)) {
        CUNIT_FAIL("%s", plan->errorMessage);
    }
    CUNIT_ASSERT_FALSE(EaglePlan_isError(plan));

    /* execute */
    EagleInstance *eagle = EagleInstance_New(cores);
    EagleInstance_addPlan(eagle, plan);
    EagleInstance_run(eagle);

    /* check results */
    EaglePage *page1 = EaglePageProvider_nextPage(plan->result[0]);
    EaglePage *page2 = EaglePageProvider_nextPage(plan->result[1]);
    CUNIT_ASSERT_NOT_NULL(page1);
    CUNIT_ASSERT_NOT_NULL(page2);

    EaglePage_Delete(page1);
    EaglePage_Delete(page2);

    EagleDbSqlExpression_DeleteRecursive((EagleDbSqlExpression*) p->yyparse_ast);
    EaglePlan_Delete(plan);
    EagleInstance_Delete(eagle);
    EagleDbParser_Delete(p);
    EagleDbInstance_Delete(db);
}