You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
MCOL-05 Modify the DDL parser to not use (even more) global variables.
This commit is contained in:
@ -21,6 +21,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "sqlparser.h"
|
||||||
#include "ddlpkg.h"
|
#include "ddlpkg.h"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -29,8 +30,9 @@
|
|||||||
#include "ddl-gram.h"
|
#include "ddl-gram.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace ddlpackage;
|
||||||
int lineno = 1;
|
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);
|
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;
|
typedef std::vector<char*> valbuf_t;
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "sqlparser.h"
|
|
||||||
using namespace ddlpackage;
|
using namespace ddlpackage;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -56,21 +56,20 @@
|
|||||||
#include "ddl-gram.h"
|
#include "ddl-gram.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define scanner x->scanner
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ddlpackage;
|
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);
|
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);
|
char* copy_string(const char *str);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%expect 15
|
%expect 15
|
||||||
%pure-parser
|
%pure-parser
|
||||||
%lex-param {void * scanner}
|
%lex-param {void * scanner}
|
||||||
%parse-param {void * scanner}
|
%parse-param {struct pass_to_bison * x}
|
||||||
%debug
|
%debug
|
||||||
|
|
||||||
/* Bison uses this to generate a C union definition. This is used to
|
/* 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
|
%type <sqlStmt> trunc_table_statement
|
||||||
|
|
||||||
%%
|
%%
|
||||||
stmtblock: stmtmulti { parseTree = $1; }
|
stmtblock: stmtmulti { x->fParseTree = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -220,11 +219,9 @@ stmtmulti:
|
|||||||
}
|
}
|
||||||
| stmt
|
| stmt
|
||||||
{
|
{
|
||||||
/* The user is supposed to supply a ParseTree* via grammar_init.
|
|
||||||
So, it is already there. */
|
|
||||||
if ($1 != NULL)
|
if ($1 != NULL)
|
||||||
{
|
{
|
||||||
$$ = parseTree;
|
$$ = x->fParseTree;
|
||||||
$$->push_back($1);
|
$$->push_back($1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -601,8 +598,8 @@ table_name:
|
|||||||
qualified_name:
|
qualified_name:
|
||||||
IDENT '.' IDENT {$$ = new QualifiedName($1, $3);}
|
IDENT '.' IDENT {$$ = new QualifiedName($1, $3);}
|
||||||
| IDENT {
|
| IDENT {
|
||||||
if (db_schema.size())
|
if (x->fDBSchema.size())
|
||||||
$$ = new QualifiedName((char*)db_schema.c_str(), $1);
|
$$ = new QualifiedName((char*)x->fDBSchema.c_str(), $1);
|
||||||
else
|
else
|
||||||
$$ = new QualifiedName($1);
|
$$ = 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;
|
|
||||||
}
|
|
||||||
|
@ -37,17 +37,17 @@
|
|||||||
|
|
||||||
void scanner_finish(void* yyscanner);
|
void scanner_finish(void* yyscanner);
|
||||||
void scanner_init(const char *str, 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_init_extra(void* user_defined,void** yyscanner);
|
||||||
int ddllex_destroy(void* yyscanner);
|
int ddllex_destroy(void* yyscanner);
|
||||||
int ddlparse(void* yyscanner);
|
int ddlparse(ddlpackage::pass_to_bison* x);
|
||||||
void set_schema(std::string schema);
|
void set_schema(std::string schema);
|
||||||
namespace ddlpackage {
|
namespace ddlpackage {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
SqlParser::SqlParser() :
|
SqlParser::SqlParser() :
|
||||||
fStatus(-1),
|
fStatus(-1),
|
||||||
fDebug(false)
|
fDebug(false),
|
||||||
|
x(&fParseTree)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,15 +59,14 @@ namespace ddlpackage {
|
|||||||
|
|
||||||
void SqlParser::setDefaultSchema(std::string schema)
|
void SqlParser::setDefaultSchema(std::string schema)
|
||||||
{
|
{
|
||||||
set_schema(schema);
|
x.fDBSchema=schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SqlParser::Parse(const char* sqltext)
|
int SqlParser::Parse(const char* sqltext)
|
||||||
{
|
{
|
||||||
ddllex_init_extra(&scanData, &scanner);
|
ddllex_init_extra(&scanData, &x.scanner);
|
||||||
scanner_init(sqltext, scanner);
|
scanner_init(sqltext, x.scanner);
|
||||||
grammar_init(&fParseTree, fDebug);
|
fStatus = ddlparse(&x);
|
||||||
fStatus = ddlparse(scanner);
|
|
||||||
return fStatus;
|
return fStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +88,8 @@ namespace ddlpackage {
|
|||||||
|
|
||||||
SqlParser::~SqlParser()
|
SqlParser::~SqlParser()
|
||||||
{
|
{
|
||||||
scanner_finish(scanner); // free scanner allocated memory
|
scanner_finish(x.scanner); // free scanner allocated memory
|
||||||
ddllex_destroy(scanner);
|
ddllex_destroy(x.scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +103,6 @@ namespace ddlpackage {
|
|||||||
{
|
{
|
||||||
fStatus = -1;
|
fStatus = -1;
|
||||||
|
|
||||||
int ddlparse();
|
|
||||||
ifstream ifsql;
|
ifstream ifsql;
|
||||||
ifsql.open(sqlfile.c_str());
|
ifsql.open(sqlfile.c_str());
|
||||||
if(!ifsql.is_open()) {
|
if(!ifsql.is_open()) {
|
||||||
|
@ -81,6 +81,14 @@ struct scan_data
|
|||||||
valbuf_t valbuf;
|
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
|
class SqlParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -113,10 +121,11 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
ParseTree fParseTree;
|
ParseTree fParseTree;
|
||||||
|
std::string fDBSchema;
|
||||||
int fStatus; ///< return from yyparse() stored here.
|
int fStatus; ///< return from yyparse() stored here.
|
||||||
bool fDebug; ///< Turn on bison debugging.
|
bool fDebug; ///< Turn on bison debugging.
|
||||||
void* scanner; // yyscan_t * needed for re-entrant flex scanner
|
|
||||||
scan_data scanData;
|
scan_data scanData;
|
||||||
|
pass_to_bison x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -614,14 +614,15 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
|
|||||||
{
|
{
|
||||||
SqlParser parser;
|
SqlParser parser;
|
||||||
THD *thd = current_thd;
|
THD *thd = current_thd;
|
||||||
#ifdef INFINIDB_DEBUG
|
//#ifdef INFINIDB_DEBUG
|
||||||
cout << "ProcessDDLStatement: " << schema << "." << table << ":" << ddlStatement << endl;
|
cout << "ProcessDDLStatement: " << schema << "." << table << ":" << ddlStatement << endl;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
parser.setDefaultSchema(schema);
|
parser.setDefaultSchema(schema);
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
IDBCompressInterface idbCompress;
|
IDBCompressInterface idbCompress;
|
||||||
parser.Parse(ddlStatement.c_str());
|
parser.Parse(ddlStatement.c_str());
|
||||||
|
cout << "ProcessDDLStatement: finished parse " << schema << "." << table << endl;
|
||||||
if (!thd->infinidb_vtable.cal_conn_info)
|
if (!thd->infinidb_vtable.cal_conn_info)
|
||||||
thd->infinidb_vtable.cal_conn_info = (void*)(new cal_connection_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);
|
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);
|
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
|
||||||
csc->identity(execplan::CalpontSystemCatalog::FE);
|
csc->identity(execplan::CalpontSystemCatalog::FE);
|
||||||
const ddlpackage::ParseTree &ptree = parser.GetParseTree();
|
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];
|
SqlStatement &stmt = *ptree.fList[0];
|
||||||
bool isVarbinaryAllowed = false;
|
bool isVarbinaryAllowed = false;
|
||||||
std::string valConfig = config::Config::makeConfig()->getConfig(
|
std::string valConfig = config::Config::makeConfig()->getConfig(
|
||||||
@ -1790,7 +1798,7 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
|
|||||||
rc = b;
|
rc = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (runtime_error&)
|
catch (runtime_error& e)
|
||||||
{
|
{
|
||||||
rc =1;
|
rc =1;
|
||||||
thd->get_stmt_da()->set_overwrite_status(true);
|
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);
|
std::string stmt(query);
|
||||||
algorithm::to_upper(stmt);
|
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)
|
// @bug 4158 allow table name with 'restrict' in it (but not by itself)
|
||||||
std::string::size_type fpos;
|
std::string::size_type fpos;
|
||||||
fpos = stmt.rfind(" RESTRICT");
|
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 = thd->query();
|
||||||
stmt += ";";
|
stmt += ";";
|
||||||
int rc = ProcessDDLStatement(stmt, schema, tbl, tid2sid(thd->thread_id), emsg);
|
int rc = ProcessDDLStatement(stmt, schema, tbl, tid2sid(thd->thread_id), emsg);
|
||||||
|
cout << "ProcessDDLStatement rc=" << rc << endl;
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
|
{
|
||||||
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, emsg.c_str());
|
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, emsg.c_str());
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ template <class T> bool isnan(T);
|
|||||||
#ifndef ENABLED_DEBUG_SYNC
|
#ifndef ENABLED_DEBUG_SYNC
|
||||||
#define ENABLED_DEBUG_SYNC
|
#define ENABLED_DEBUG_SYNC
|
||||||
#endif
|
#endif
|
||||||
#define INFINIDB_DEBUG
|
//#define INFINIDB_DEBUG
|
||||||
#define DBUG_ON 1
|
#define DBUG_ON 1
|
||||||
#undef DBUG_OFF
|
#undef DBUG_OFF
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user