1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-06-04 21:02:13 +03:00

MCOL-05 Modify the DDL parser to not use (even more) global variables.

This commit is contained in:
David Hall 2016-08-16 18:25:09 -05:00
parent 53abd78979
commit 0d2f496389
6 changed files with 48 additions and 42 deletions

View File

@ -21,6 +21,7 @@
#include <iostream>
#include <vector>
#include <stdio.h>
#include "sqlparser.h"
#include "ddlpkg.h"
#ifdef _MSC_VER
@ -29,8 +30,9 @@
#include "ddl-gram.h"
#endif
using namespace ddlpackage;
int lineno = 1;
void ddlerror(yyscan_t yyscanner, char *s);
void ddlerror(struct pass_to_bison* x, char const *s);
static char* scanner_copy(char *str, yyscan_t yyscanner);
@ -173,15 +175,14 @@ VARBINARY {return VARBINARY;}
%%
void ddlerror(yyscan_t yyscanner, char const *s)
void ddlerror(struct pass_to_bison* x, char const *s)
{
printf("yyerror: %d: %s at %s\n", lineno, s, ddlget_text(yyscanner));
printf("yyerror: %d: %s at %s\n", lineno, s, ddlget_text(x->scanner));
}
typedef std::vector<char*> valbuf_t;
#include <pthread.h>
#include "sqlparser.h"
using namespace ddlpackage;
/*

View File

@ -56,21 +56,20 @@
#include "ddl-gram.h"
#endif
#define scanner x->scanner
using namespace std;
using namespace ddlpackage;
/* The user is expect to pass a ParseTree* to grammar_init */
static ParseTree* parseTree;
static std::string db_schema;
int ddllex(YYSTYPE* ddllval, void* yyscanner);
void ddlerror (void* yyscanner, char const *error);
void ddlerror(struct pass_to_bison* x, char const *s);
char* copy_string(const char *str);
%}
%expect 15
%pure-parser
%lex-param {void * scanner}
%parse-param {void * scanner}
%parse-param {struct pass_to_bison * x}
%debug
/* Bison uses this to generate a C union definition. This is used to
@ -203,7 +202,7 @@ VARYING WITH ZONE DOUBLE IDB_FLOAT REAL CHARSET IDB_IF EXISTS CHANGE TRUNCATE
%type <sqlStmt> trunc_table_statement
%%
stmtblock: stmtmulti { parseTree = $1; }
stmtblock: stmtmulti { x->fParseTree = $1; }
;
@ -220,11 +219,9 @@ stmtmulti:
}
| stmt
{
/* The user is supposed to supply a ParseTree* via grammar_init.
So, it is already there. */
if ($1 != NULL)
{
$$ = parseTree;
$$ = x->fParseTree;
$$->push_back($1);
}
else
@ -601,8 +598,8 @@ table_name:
qualified_name:
IDENT '.' IDENT {$$ = new QualifiedName($1, $3);}
| IDENT {
if (db_schema.size())
$$ = new QualifiedName((char*)db_schema.c_str(), $1);
if (x->fDBSchema.size())
$$ = new QualifiedName((char*)x->fDBSchema.c_str(), $1);
else
$$ = new QualifiedName($1);
}
@ -1065,15 +1062,4 @@ opt_column:
%%
void grammar_init(ParseTree *_parseTree, bool debug)
{
parseTree = _parseTree;
if(debug)
yydebug = 1;
}
void set_schema(std::string schema)
{
db_schema = schema;
}

View File

@ -37,17 +37,17 @@
void scanner_finish(void* yyscanner);
void scanner_init(const char *str, void* yyscanner);
void grammar_init(ddlpackage::ParseTree *ptree, bool);
int ddllex_init_extra(void* user_defined,void** yyscanner);
int ddllex_destroy(void* yyscanner);
int ddlparse(void* yyscanner);
int ddlparse(ddlpackage::pass_to_bison* x);
void set_schema(std::string schema);
namespace ddlpackage {
using namespace std;
SqlParser::SqlParser() :
fStatus(-1),
fDebug(false)
fDebug(false),
x(&fParseTree)
{
}
@ -59,15 +59,14 @@ namespace ddlpackage {
void SqlParser::setDefaultSchema(std::string schema)
{
set_schema(schema);
x.fDBSchema=schema;
}
int SqlParser::Parse(const char* sqltext)
{
ddllex_init_extra(&scanData, &scanner);
scanner_init(sqltext, scanner);
grammar_init(&fParseTree, fDebug);
fStatus = ddlparse(scanner);
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
}
@ -89,8 +88,8 @@ namespace ddlpackage {
SqlParser::~SqlParser()
{
scanner_finish(scanner); // free scanner allocated memory
ddllex_destroy(scanner);
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
}
@ -104,7 +103,6 @@ namespace ddlpackage {
{
fStatus = -1;
int ddlparse();
ifstream ifsql;
ifsql.open(sqlfile.c_str());
if(!ifsql.is_open()) {

View File

@ -81,6 +81,14 @@ struct scan_data
valbuf_t valbuf;
};
struct pass_to_bison {
ParseTree* fParseTree;
std::string fDBSchema;
void* scanner;
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL) {};
};
class SqlParser
{
public:
@ -113,10 +121,11 @@ public:
protected:
ParseTree fParseTree;
std::string fDBSchema;
int fStatus; ///< return from yyparse() stored here.
bool fDebug; ///< Turn on bison debugging.
void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData;
pass_to_bison x;
};

View File

@ -614,14 +614,15 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
{
SqlParser parser;
THD *thd = current_thd;
#ifdef INFINIDB_DEBUG
//#ifdef INFINIDB_DEBUG
cout << "ProcessDDLStatement: " << schema << "." << table << ":" << ddlStatement << endl;
#endif
//#endif
parser.setDefaultSchema(schema);
int rc = 0;
IDBCompressInterface idbCompress;
parser.Parse(ddlStatement.c_str());
cout << "ProcessDDLStatement: finished parse " << schema << "." << table << endl;
if (!thd->infinidb_vtable.cal_conn_info)
thd->infinidb_vtable.cal_conn_info = (void*)(new cal_connection_info());
cal_connection_info* ci = reinterpret_cast<cal_connection_info*>(thd->infinidb_vtable.cal_conn_info);
@ -630,6 +631,13 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
csc->identity(execplan::CalpontSystemCatalog::FE);
const ddlpackage::ParseTree &ptree = parser.GetParseTree();
if (UNLIKELY(ptree.fList.size() == 0))
{
// TODO: Once the crash bug is found, this should convert to "return 0"
cout << "***** ProcessDDLStatement has no stmt *****" << endl;
setError(thd, ER_CHECK_NOT_IMPLEMENTED, "DDL processed without statement");
return 1;
}
SqlStatement &stmt = *ptree.fList[0];
bool isVarbinaryAllowed = false;
std::string valConfig = config::Config::makeConfig()->getConfig(
@ -1790,7 +1798,7 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
rc = b;
}
}
catch (runtime_error&)
catch (runtime_error& e)
{
rc =1;
thd->get_stmt_da()->set_overwrite_status(true);
@ -2071,6 +2079,7 @@ int ha_calpont_impl_delete_table_(const char *db, const char *name, cal_connecti
}
std::string stmt(query);
algorithm::to_upper(stmt);
cout << "ha_calpont_impl_delete_table: " << schema.c_str() << "." << tbl.c_str() << " " << stmt.c_str() << endl;
// @bug 4158 allow table name with 'restrict' in it (but not by itself)
std::string::size_type fpos;
fpos = stmt.rfind(" RESTRICT");
@ -2096,8 +2105,11 @@ int ha_calpont_impl_delete_table_(const char *db, const char *name, cal_connecti
stmt = thd->query();
stmt += ";";
int rc = ProcessDDLStatement(stmt, schema, tbl, tid2sid(thd->thread_id), emsg);
cout << "ProcessDDLStatement rc=" << rc << endl;
if (rc != 0)
{
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, emsg.c_str());
}
return rc;
}

View File

@ -45,7 +45,7 @@ template <class T> bool isnan(T);
#ifndef ENABLED_DEBUG_SYNC
#define ENABLED_DEBUG_SYNC
#endif
#define INFINIDB_DEBUG
//#define INFINIDB_DEBUG
#define DBUG_ON 1
#undef DBUG_OFF
#else