Skip to content

Commit

Permalink
Added SHOW TABLES, DESCRIBE and DROP TABLE commands
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmks committed Apr 1, 2014
1 parent be14be0 commit e207860
Show file tree
Hide file tree
Showing 8 changed files with 2,377 additions and 2,253 deletions.
963 changes: 526 additions & 437 deletions bison.cu

Large diffs are not rendered by default.

2,954 changes: 1,436 additions & 1,518 deletions bison.tab.c

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions bison.tab.h
Expand Up @@ -102,7 +102,12 @@
THEN = 318,
ELSE = 319,
END = 320,
REFERENCES = 321
REFERENCES = 321,
SHOW = 322,
TABLES = 323,
TABLE = 324,
DESCRIBE = 325,
DROP = 326
};
#endif

Expand All @@ -113,7 +118,7 @@ typedef union YYSTYPE
{

/* Line 1676 of yacc.c */
#line 75 "bison.y"
#line 78 "bison.y"

int intval;
double floatval;
Expand All @@ -123,7 +128,7 @@ typedef union YYSTYPE


/* Line 1676 of yacc.c */
#line 127 "bison.tab.h"
#line 132 "bison.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
Expand Down
74 changes: 70 additions & 4 deletions bison.y
Expand Up @@ -69,6 +69,9 @@
void emit_presort(char* s);
void emit_display(char *s, char* sep);
void emit_case();
void emit_show_tables();
void emit_describe_table(char* table_name);
void emit_drop_table(char* table_name);

%}

Expand Down Expand Up @@ -150,7 +153,11 @@
%token ELSE
%token END
%token REFERENCES

%token SHOW
%token TABLES
%token TABLE
%token DESCRIBE
%token DROP

%type <intval> load_list opt_where opt_limit sort_def del_where
%type <intval> val_list opt_val_list expr_list opt_group_list join_list
Expand Down Expand Up @@ -191,8 +198,15 @@ NAME ASSIGN SELECT expr_list FROM NAME opt_group_list
{ emit_insert($3, $7);}
| DISPLAY NAME USING '(' FILENAME ')' opt_limit
{ emit_display($2, $5);}
| SHOW TABLES
{ emit_show_tables();}
| DESCRIBE NAME
{ emit_describe_table($2);}
| DROP TABLE NAME
{ emit_drop_table($3);}
;


expr:
NAME { emit_name($1); }
| NAME '.' NAME { emit("FIELDNAME %s.%s", $1, $3); }
Expand Down Expand Up @@ -341,6 +355,7 @@ map<unsigned int, unsigned int> join_and_cnt;
bool scan_state = 0;
ContextPtr context;
map<string, map<string, bool> > used_vars;
bool save_dict = 0;

void emit_multijoin(string s, string j1, string j2, unsigned int tab, char* res_name);
void filter_op(char *s, char *f, unsigned int segment);
Expand Down Expand Up @@ -2013,7 +2028,7 @@ void emit_display(char *f, char* sep)
limit = op_nums.front();
op_nums.pop();
};

//a->Store("",sep, limit, 0, 1);
a->Display(limit, 0, 1);
if(verbose)
Expand Down Expand Up @@ -2286,6 +2301,56 @@ void emit_load(char *s, char *f, int d, char* sep)
};
}

void emit_show_tables()
{
if (scan_state == 1) {
for ( map<string, map<string, col_data> >::iterator it=data_dict.begin() ; it != data_dict.end(); ++it ) {
cout << (*it).first << endl;
};
};

return;
}

void emit_drop_table(char* table_name)
{
if (scan_state == 1) {
if(data_dict.find(table_name) != data_dict.end()) {
data_dict.erase(table_name);
};
save_dict = 1;
};

return;
}


void emit_describe_table(char* table_name)
{
if (scan_state == 1) {
map<string, map<string, col_data> >::iterator iter;
if((iter = data_dict.find(table_name)) != data_dict.end()) {
map<string, col_data> s = (*iter).second;
for ( map<string, col_data>::iterator it=s.begin() ; it != s.end(); ++it ) {
if ((*it).second.col_type == 0) {
cout << (*it).first << " integer" << endl;
}
else if ((*it).second.col_type == 1) {
cout << (*it).first << " float" << endl;
}
else if ((*it).second.col_type == 3) {
cout << (*it).first << " decimal" << endl;
}
else {
cout << (*it).first << " char(" << (*it).second.col_length << ")" << endl;
};
};
};
};

return;
}



void yyerror(char *s, ...)
Expand Down Expand Up @@ -2421,7 +2486,7 @@ bool interactive = 0;
};

if(verbose) {
//cout<< endl << "tot disk time " << (( tot ) / (double)CLOCKS_PER_SEC ) << endl;
cout<< endl << "tot disk time " << (( tot ) / (double)CLOCKS_PER_SEC ) << endl;
cout<< "cycle time " << ( ( std::clock() - start1 ) / (double)CLOCKS_PER_SEC ) << " " << getFreeMem() << endl;
};
}
Expand Down Expand Up @@ -2474,7 +2539,8 @@ bool interactive = 0;


};
save_col_data(data_dict,"data.dictionary");
if(save_dict)
save_col_data(data_dict,"data.dictionary");
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions cm.cu
Expand Up @@ -1561,6 +1561,7 @@ void CudaSet::Store(string file_name, char* sep, unsigned int limit, bool binary
else
data_dict[file_name][columnNames[j]].col_length = char_size[columnNames[j]];
};
save_dict = 1;


if(text_source) { //writing a binary file using a text file as a source
Expand Down
1 change: 1 addition & 0 deletions cm.h
Expand Up @@ -88,6 +88,7 @@ extern map<string,string> setMap; //map to keep track of column names and set na
extern std::clock_t tot;
extern std::clock_t tot_fil;
extern bool verbose;
extern bool save_dict;
extern ContextPtr context;


Expand Down
5 changes: 5 additions & 0 deletions fl.l
Expand Up @@ -74,6 +74,11 @@ THEN {return THEN; }
ELSE {return ELSE; }
END {return END; }
REFERENCES {return REFERENCES; }
SHOW {return SHOW; }
TABLES {return TABLES; }
TABLE {return TABLE; }
DESCRIBE {return DESCRIBE; }
DROP {return DROP; }


[0-9]+ { yylval.intval = atoi(yytext); return INTNUM; }
Expand Down

0 comments on commit e207860

Please sign in to comment.