static rasqal_rowsource* rasqal_algebra_join_algebra_node_to_rowsource(rasqal_engine_algebra_data* execution_data, rasqal_algebra_node* node, rasqal_engine_error *error_p) { rasqal_query *query = execution_data->query; rasqal_rowsource *left_rs; rasqal_rowsource *right_rs; left_rs = rasqal_algebra_node_to_rowsource(execution_data, node->node1, error_p); if(!left_rs || *error_p) return NULL; right_rs = rasqal_algebra_node_to_rowsource(execution_data, node->node2, error_p); if(!right_rs || *error_p) { rasqal_free_rowsource(left_rs); return NULL; } return rasqal_new_join_rowsource(query->world, query, left_rs, right_rs, RASQAL_JOIN_TYPE_NATURAL, node->expr); }
int main(int argc, char *argv[]) { const char *program = rasqal_basename(argv[0]); rasqal_rowsource *rowsource = NULL; rasqal_rowsource *left_rs = NULL; rasqal_rowsource *right_rs = NULL; rasqal_world* world = NULL; rasqal_query* query = NULL; int count; raptor_sequence* seq = NULL; int failures = 0; rasqal_variables_table* vt; int size; int expected_size = EXPECTED_COLUMNS_COUNT; int i; raptor_sequence* vars_seq = NULL; int test_count; world = rasqal_new_world(); rasqal_world_open(world); query = rasqal_new_query(world, "sparql", NULL); vt = query->vars_table; for(test_count = 0; test_count < JOIN_TESTS_COUNT; test_count++) { rasqal_join_type join_type = join_test_config[test_count].join_type; int expected_count = join_test_config[test_count].expected; int vars_count; fprintf(stderr, "%s: test #%d join type %d\n", program, test_count, RASQAL_GOOD_CAST(int, join_type)); /* 2 variables and 3 rows */ vars_count = 2; seq = rasqal_new_row_sequence(world, vt, join_1_data_2x3_rows, vars_count, &vars_seq); if(!seq) { fprintf(stderr, "%s: failed to create left sequence of %d vars\n", program, vars_count); failures++; goto tidy; } left_rs = rasqal_new_rowsequence_rowsource(world, query, vt, seq, vars_seq); if(!left_rs) { fprintf(stderr, "%s: failed to create left rowsource\n", program); failures++; goto tidy; } /* vars_seq and seq are now owned by left_rs */ vars_seq = seq = NULL; /* 3 variables and 2 rows */ vars_count = 3; seq = rasqal_new_row_sequence(world, vt, join_2_data_3x2_rows, vars_count, &vars_seq); if(!seq) { fprintf(stderr, "%s: failed to create right sequence of %d rows\n", program, vars_count); failures++; goto tidy; } right_rs = rasqal_new_rowsequence_rowsource(world, query, vt, seq, vars_seq); if(!right_rs) { fprintf(stderr, "%s: failed to create right rowsource\n", program); failures++; goto tidy; } /* vars_seq and seq are now owned by right_rs */ vars_seq = seq = NULL; rowsource = rasqal_new_join_rowsource(world, query, left_rs, right_rs, join_type, NULL); if(!rowsource) { fprintf(stderr, "%s: failed to create join rowsource\n", program); failures++; goto tidy; } /* left_rs and right_rs are now owned by rowsource */ left_rs = right_rs = NULL; seq = rasqal_rowsource_read_all_rows(rowsource); if(!seq) { fprintf(stderr, "%s: read_rows returned a NULL seq for a join rowsource\n", program); failures++; goto tidy; } count = raptor_sequence_size(seq); if(count != expected_count) { fprintf(stderr, "%s: read_rows returned %d rows for a join rowsource, expected %d\n", program, count, expected_count); failures++; goto tidy; } size = rasqal_rowsource_get_size(rowsource); if(size != expected_size) { fprintf(stderr, "%s: read_rows returned %d columns (variables) for a join rowsource, expected %d\n", program, size, expected_size); failures++; goto tidy; } for(i = 0; i < expected_size; i++) { rasqal_variable* v; const char* name = NULL; const char *expected_name = join_result_vars[i]; v = rasqal_rowsource_get_variable_by_offset(rowsource, i); if(!v) { fprintf(stderr, "%s: read_rows had NULL column (variable) #%d expected %s\n", program, i, expected_name); failures++; goto tidy; } name = RASQAL_GOOD_CAST(const char*, v->name); if(strcmp(name, expected_name)) { fprintf(stderr, "%s: read_rows returned column (variable) #%d %s but expected %s\n", program, i, name, expected_name); failures++; goto tidy; } } #ifdef RASQAL_DEBUG rasqal_rowsource_print_row_sequence(rowsource, seq, DEBUG_FH); #endif raptor_free_sequence(seq); seq = NULL; rasqal_free_rowsource(rowsource); rowsource = NULL; /* end test_count loop */ } tidy: if(seq) raptor_free_sequence(seq); if(left_rs) rasqal_free_rowsource(left_rs); if(right_rs) rasqal_free_rowsource(right_rs); if(rowsource) rasqal_free_rowsource(rowsource); if(query) rasqal_free_query(query); if(world) rasqal_free_world(world); return failures; }