use of org.hsqldb_voltpatches.HSQLDDLInfo in project voltdb by VoltDB.
the class HSQLLexer method preprocessHSQLDDL.
//===== Public interface
/**
* Glean some basic info about DDL statements sent to HSQLDB
*/
public static HSQLDDLInfo preprocessHSQLDDL(String ddl) {
ddl = SQLLexer.stripComments(ddl);
Matcher matcher = HSQL_DDL_PREPROCESSOR.matcher(ddl);
if (matcher.find()) {
String verbString = matcher.group("verb");
HSQLDDLInfo.Verb verb = HSQLDDLInfo.Verb.get(verbString);
if (verb == null) {
return null;
}
String nounString = matcher.group("object");
HSQLDDLInfo.Noun noun = HSQLDDLInfo.Noun.get(nounString);
if (noun == null) {
return null;
}
boolean createStream = verb.equals(HSQLDDLInfo.Verb.CREATE) && noun.equals(HSQLDDLInfo.Noun.STREAM);
String name = matcher.group("name");
if (name == null) {
return null;
}
String secondName = matcher.group("subject");
if (secondName != null) {
secondName = secondName.toLowerCase();
}
// cascade/if exists are interesting on alters and drops
boolean cascade = false;
boolean ifexists = false;
if (verb != HSQLDDLInfo.Verb.CREATE) {
matcher = DDL_IFEXISTS_OR_CASCADE_CHECK.matcher(ddl);
if (matcher.matches()) {
// Don't be too sensitive to regex specifics by assuming null always
// indicates a missing clause. Look for empty too.
String existsClause = matcher.group("exists");
String cascadeClause = matcher.group("cascade");
ifexists = existsClause != null && !existsClause.isEmpty();
cascade = cascadeClause != null && !cascadeClause.isEmpty();
}
}
return new HSQLDDLInfo(verb, noun, name.toLowerCase(), secondName, cascade, ifexists, createStream);
}
return null;
}
use of org.hsqldb_voltpatches.HSQLDDLInfo in project voltdb by VoltDB.
the class DDLCompiler method processVoltDBStatements.
private void processVoltDBStatements(final Database db, final DdlProceduresToLoad whichProcs, DDLStatement stmt) throws VoltCompilerException {
boolean processed = false;
try {
// Process a VoltDB-specific DDL statement, like PARTITION, REPLICATE,
// CREATE PROCEDURE, CREATE FUNCTION, and CREATE ROLE.
processed = m_voltStatementProcessor.process(stmt, db, whichProcs);
} catch (VoltCompilerException e) {
// Reformat the message thrown by VoltDB DDL processing to have a line number.
String msg = "VoltDB DDL Error: \"" + e.getMessage() + "\" in statement starting on lineno: " + stmt.lineNo;
throw m_compiler.new VoltCompilerException(msg);
}
if (!processed) {
try {
//* enable to debug */ System.out.println("DEBUG: " + stmt.statement);
// kind of ugly. We hex-encode each statement so we can
// avoid embedded newlines so we can delimit statements
// with newline.
m_fullDDL += Encoder.hexEncode(stmt.statement) + "\n";
// figure out what table this DDL might affect to minimize diff processing
HSQLDDLInfo ddlStmtInfo = HSQLLexer.preprocessHSQLDDL(stmt.statement);
// Get the diff that results from applying this statement and apply it
// to our local tree (with Volt-specific additions)
VoltXMLDiff thisStmtDiff = m_hsql.runDDLCommandAndDiff(ddlStmtInfo, stmt.statement);
// null diff means no change (usually drop if exists for non-existent thing)
if (thisStmtDiff != null) {
applyDiff(thisStmtDiff);
}
// special treatment for stream syntax
if (ddlStmtInfo.creatStream) {
processCreateStreamStatement(stmt, db, whichProcs);
}
} catch (HSQLParseException e) {
String msg = "DDL Error: \"" + e.getMessage() + "\" in statement starting on lineno: " + stmt.lineNo;
throw m_compiler.new VoltCompilerException(msg, stmt.lineNo);
}
}
}
use of org.hsqldb_voltpatches.HSQLDDLInfo in project voltdb by VoltDB.
the class TestSQLLexer method checkInvalidHSQLPreprocessing.
void checkInvalidHSQLPreprocessing(String ddl) {
HSQLDDLInfo info = HSQLLexer.preprocessHSQLDDL(ddl);
assertEquals(null, info);
}
use of org.hsqldb_voltpatches.HSQLDDLInfo in project voltdb by VoltDB.
the class TestSQLLexer method checkValidHSQLPreprocessing.
void checkValidHSQLPreprocessing(String ddl, HSQLDDLInfo.Verb verb, HSQLDDLInfo.Noun noun, String name, String secondName, boolean ifexists, boolean cascade) {
HSQLDDLInfo info = HSQLLexer.preprocessHSQLDDL(ddl);
assertNotNull(info);
assertEquals(verb, info.verb);
assertEquals(noun, info.noun);
assertEquals(name, info.name);
assertEquals(secondName, info.secondName);
assertEquals(ifexists, info.ifexists);
assertEquals(cascade, info.cascade);
}
Aggregations