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); }
CUNIT_TEST(MemorySuite, EaglePlan_New_3) { EagleMemory_MockInit(); EagleMemory_Mock("EaglePlan_New.3"); EaglePlan *plan = EaglePlan_New(1, 1); CUNIT_ASSERT_NULL(plan); EaglePlan_Delete(plan); CUNIT_ASSERT_EQUAL_INT(EagleMemory_GetMockInvocations(), 1); EagleMemory_MockFinish(); }
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); }
CUNIT_TEST(DBSuite, EagleDbSqlExpression_CompilePlanIntoBuffer_2) { EagleDbSqlExpression *op = (EagleDbSqlExpression*) EagleDbSqlUnaryExpression_New(EagleDbSqlUnaryExpressionOperatorNot, NULL); EagleDbSqlExpression *expr = (EagleDbSqlExpression*) EagleDbSqlUnaryExpression_New(EagleDbSqlUnaryExpressionOperatorNot, op); EaglePlan *plan = EaglePlan_New(1, 1); EaglePlan_prepareBuffers(plan, 10); int destinationBuffer = 0; int result = EagleDbSqlExpression_CompilePlanIntoBuffer_(expr, &destinationBuffer, plan, EagleTrue); CUNIT_VERIFY_EQUAL_INT(result, EagleDbSqlExpression_ERROR); EagleDbSqlExpression_DeleteRecursive(expr); EaglePlan_Delete(plan); }
CUNIT_TEST(DBSuite, EagleDbSqlExpression_CompilePlanIntoBuffer_Value_) { EagleDbSqlValue *value = EagleDbSqlValue_NewWithString("abc", EagleFalse); int destinationBuffer = 1; EaglePlan *plan = EaglePlan_New(10, 1); EaglePlan_prepareBuffers(plan, 3); EagleDbSqlExpression_CompilePlanIntoBuffer_Value_((EagleDbSqlExpression*) value, &destinationBuffer, plan, EagleFalse); CUNIT_VERIFY_EQUAL_INT(plan->bufferTypes[destinationBuffer], EagleDataTypeVarchar); EaglePlan_Delete(plan); EagleDbSqlValue_Delete(value); }
CUNIT_TEST(DBSuite, EagleDbSqlExpression_CompilePlanIntoBuffer_Cast_) { EagleDbSqlCastExpression *expr = EagleDbSqlCastExpression_New(NULL, EagleDataTypeFloat); int destinationBuffer = 0; EaglePlan *plan = EaglePlan_New(1, 1); EaglePlan_prepareBuffers(plan, 10); CUNIT_VERIFY_EQUAL_INT(EagleDbSqlExpression_CompilePlanIntoBuffer_Cast_((EagleDbSqlExpression*) expr, &destinationBuffer, plan), EagleDbSqlExpression_ERROR); EagleDbSqlExpression_DeleteRecursive((EagleDbSqlExpression*) expr); EaglePlan_Delete(plan); }
CUNIT_TEST(DBSuite, EagleDbSqlExpression_CompilePlanIntoBuffer_Unary_) { EagleDbSqlUnaryExpression *expr = EagleDbSqlUnaryExpression_New(EagleDbSqlUnaryExpressionOperatorNot, (EagleDbSqlExpression*) EagleDbSqlValue_NewWithFloat(123.456)); int destinationBuffer = 0; EaglePlan *plan = EaglePlan_New(1, 1); EaglePlan_prepareBuffers(plan, 10); EagleDbSqlExpression_CompilePlanIntoBuffer_Unary_((EagleDbSqlExpression*) expr, &destinationBuffer, plan); CUNIT_ASSERT_EQUAL_STRING(plan->errorMessage, "No such unary operator NOT FLOAT"); EagleDbSqlExpression_DeleteRecursive((EagleDbSqlExpression*) expr); EaglePlan_Delete(plan); }
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); }