BadgerDB
/afs/cs.wisc.edu/u/n/w/nwilliam/private/workspace/Quut/src/parser/SqlInterp.h
00001 //
00002 // Author: Jignesh M. Patel
00003 //         EECS Department, University of Michigan
00004 // Date:   August 2000
00005 //
00006 
00013 #ifndef SQL_INTERP_H
00014 #define SQL_INTERP_H
00015 
00016 #include <iostream>
00017 //#include <string.h>
00018 #include <cassert>
00019 // #include "Catalog.h"
00020 // #include "Error.h"
00021 // #include "Helper.h"
00022 // #include "Operators.h"
00023 // #include "Select.h"
00024 //
00025 // Class encapsulating the SQL Interpreter
00026 //
00027 // TODO: The fun stuff, typecheck the parse tree, optimize then execute - JmP
00028 //
00029 class PxxInterp
00030 {
00031 public:
00032    static void eval(PxxPnode *ptree);
00033    static void quit(void);
00034 
00035    // create/delete table
00036    static void createTable(PxxPnode *ptree);
00037    static void deleteTable(PxxDrop *ptree);
00038 
00039    // insert tuples into a table.
00040    static void insertIntoTable(PxxPnode *ptree);
00041 
00042    // process a query
00043    static void processQuery(PxxPnode *ptree);
00044 
00045    // create/delete indices
00046    static void createIndex(PxxCreateIndex *pIdxCreate);
00047    static void deleteIndex(PxxDropIndex *pIdxCreate);
00048 };
00049 
00050 
00051 //
00052 // ATTR_DESCR: attribute descriptor
00053 //
00054 
00055 typedef struct {
00056   char *attrName;                       // relation name
00057   int attrType;                         // type of attribute
00058   int attrLen;                          // length of attribute
00059 } ATTR_DESCR;
00060 
00061 
00062 //
00063 // REL_ATTR: describes a qualified attribute (relName.attrName)
00064 //
00065 
00066 typedef struct {
00067   char *relName;                        // relation name
00068   char *attrName;                       // attribute name
00069 } REL_ATTR;
00070 
00071 //
00072 // ATTR_VAL: <attribute, value> pair
00073 //
00074 
00075 typedef struct {
00076   char *attrName;                       // attribute name
00077   int valType;                          // type of value
00078   int valLength;                        // length if type = STRING_TYPE
00079   void *value;                          // value for attribute
00080 } ATTR_VAL;
00081 
00082 
00083 #define INTCHAR   'i'
00084 #define FLOATCHAR 'f'
00085 #define STRCHAR   's'
00086 #define PROMPT    "\n>>> "
00087 
00088 
00089 //
00090 // all the available kinds of nodes
00091 //
00092 
00093 typedef enum {
00094     N_QUERY,
00095     N_INSERT,
00096     N_DELETE,
00097     N_CREATE,
00098     N_DESTROY,
00099     N_BUILD,
00100     N_REBUILD,
00101     N_DROP,
00102     N_LOAD,
00103     N_PRINT,
00104     N_HELP,
00105     N_SELECT,
00106     N_JOIN,
00107     N_PRIMATTR,
00108     N_QUALATTR,
00109     N_ATTRVAL,
00110     N_ATTRTYPE,
00111     N_VALUE,
00112     N_LIST
00113 } NODEKIND;
00114 
00115 
00116 //
00117 // structure of parse tree nodes
00118 //
00119 
00120 typedef struct node {
00121     NODEKIND kind;
00122 
00123     union {
00124   // query node */
00125   struct {
00126       char *relname;
00127       struct node *attrlist;
00128       struct node *qual;
00129   } QUERY;
00130 
00131   // insert node */
00132   struct {
00133       char *relname;
00134       struct node *attrlist;
00135   } INSERT;
00136 
00137   // delete node */
00138   struct {
00139       char *relname;
00140       struct node *qual;
00141   } DELETE;
00142 
00143   // create node */
00144   struct {
00145       char *relname;
00146       struct node *attrlist;
00147       struct node *primattr;
00148   } CREATE;
00149 
00150   // destroy node */
00151   struct {
00152       char *relname;
00153   } DESTROY;
00154 
00155   // re/build node */
00156   struct {
00157       char *relname;
00158       char *attrname;
00159       int nbuckets;
00160   } BUILD;
00161 
00162   // drop node */
00163   struct {
00164       char *relname;
00165       char *attrname;
00166   } DROP;
00167 
00168   // load node */
00169   struct {
00170       char *relname;
00171       char *filename;
00172   } LOAD;
00173 
00174   // pprint node */
00175   struct {
00176       char *relname;
00177   } PRINT;
00178 
00179   // help node */
00180   struct {
00181       char *relname;
00182   } HELP;
00183 
00184   // select node */
00185   struct {
00186       struct node *selattr;
00187       int op;
00188       struct node *value;
00189   } SELECT;
00190 
00191   // join node */
00192   struct {
00193       struct node *joinattr1;
00194       int op;
00195       struct node *joinattr2;
00196   } JOIN;
00197 
00198   // qualified attribute node */
00199   struct {
00200       char *relname;
00201       char *attrname;
00202   } QUALATTR;
00203 
00204   // primary attribute node */
00205   struct {
00206       char *attrname;
00207       int nbuckets;
00208   } PRIMATTR;
00209 
00210   // <attribute, value> pair */
00211   struct {
00212       char *attrname;
00213       struct node *value;
00214   } ATTRVAL;
00215 
00216   // <attribute, type> pair */
00217   struct {
00218       char *attrname;
00219       char *type;
00220   } ATTRTYPE;
00221 
00222   // <value, type> pair */
00223   struct {
00224       int type;
00225       int len;
00226       union {
00227     int ival;
00228     float rval;
00229     char *sval;
00230       } u;
00231   } VALUE;
00232 
00233   // list node */
00234   struct {
00235     struct node *self;
00236     struct node *next;
00237   } LIST;
00238     } u;
00239 } NODE;
00240 
00241 
00242 //
00243 // function prototypes
00244 //
00245 
00246 NODE *newnode(int kind);
00247 NODE *query_node(char *relname, NODE *attrlist, NODE *n);
00248 NODE *insert_node(char *relname, NODE *attrlist);
00249 NODE *delete_node(char *relname, NODE *qual);
00250 NODE *create_node(char *relname, NODE *attrlist, NODE *primattr);
00251 NODE *destroy_node(char *relname);
00252 NODE *build_node(char *relname, char *attrname, int nbuckets);
00253 NODE *rebuild_node(char *relname, char *attrname, int nbuckets);
00254 NODE *drop_node(char *relname, char *attrname);
00255 NODE *load_node(char *relname, char *filename);
00256 NODE *print_node(char *relname);
00257 NODE *help_node(char *relname);
00258 NODE *select_node(NODE *selattr, int op, NODE *value);
00259 NODE *join_node(NODE *joinattr1, int op, NODE *joinattr2);
00260 NODE *qualattr_node(char *relname, char *attrname);
00261 NODE *primattr_node(char *attrname, int nbuckets);
00262 NODE *attrval_node(char *attrname, NODE *value);
00263 NODE *attrtype_node(char *attrname, char *type);
00264 NODE *int_node(int ival);
00265 NODE *float_node(float rval);
00266 NODE *string_node(char *s);
00267 NODE *list_node(NODE *n);
00268 NODE *prepend(NODE *n, NODE *list);
00269 
00270 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends