Search in sources :

Example 1 with Feedback

use of org.voltdb.compiler.VoltCompiler.Feedback in project voltdb by VoltDB.

the class ReportMaker method getStatsHTML.

/**
     * Get some embeddable HTML of some generic catalog/application stats
     * that is drawn on the first page of the report.
     */
static String getStatsHTML(Database db, long requiredHeap, ArrayList<Feedback> warnings) {
    StringBuilder sb = new StringBuilder();
    sb.append("<table class='table table-condensed'>\n");
    // count things
    int indexes = 0, views = 0, statements = 0;
    int partitionedTables = 0, replicatedTables = 0;
    int partitionedProcs = 0, replicatedProcs = 0;
    int readProcs = 0, writeProcs = 0;
    for (Table t : db.getTables()) {
        if (t.getMaterializer() != null) {
            views++;
        } else {
            if (t.getIsreplicated()) {
                replicatedTables++;
            } else {
                partitionedTables++;
            }
        }
        indexes += t.getIndexes().size();
    }
    for (Procedure p : db.getProcedures()) {
        // skip auto-generated crud procs
        if (p.getDefaultproc()) {
            continue;
        }
        if (p.getSinglepartition()) {
            partitionedProcs++;
        } else {
            replicatedProcs++;
        }
        if (p.getReadonly()) {
            readProcs++;
        } else {
            writeProcs++;
        }
        statements += p.getStatements().size();
    }
    // version
    sb.append("<tr><td>Generated by VoltDB Version</td><td>");
    sb.append(VoltDB.instance().getVersionString()).append("</td></tr>\n");
    // timestamp
    sb.append("<tr><td>Last Schema Update on</td><td>");
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
    sb.append(sdf.format(m_timestamp)).append("</td></tr>\n");
    // tables
    sb.append("<tr><td>Table Count</td><td>");
    sb.append(String.format("%d (%d partitioned / %d replicated)", partitionedTables + replicatedTables, partitionedTables, replicatedTables));
    sb.append("</td></tr>\n");
    // views
    sb.append("<tr><td>Materialized View Count</td><td>").append(views).append("</td></tr>\n");
    // indexes
    sb.append("<tr><td>Index Count</td><td>").append(indexes).append("</td></tr>\n");
    // procedures
    sb.append("<tr><td>Procedure Count</td><td>");
    sb.append(String.format("%d (%d partitioned / %d replicated) (%d read-only / %d read-write)", partitionedProcs + replicatedProcs, partitionedProcs, replicatedProcs, readProcs, writeProcs));
    sb.append("</td></tr>\n");
    // statements
    sb.append("<tr><td>SQL Statement Count</td><td>").append(statements).append("</td></tr>\n");
    //heap
    sb.append("<tr><td>Required Java Heap</td><td>").append(requiredHeap).append(" Megabytes").append("</td></tr>\n");
    long megabytes = 1024 * 1024;
    long configuredHeap = Runtime.getRuntime().maxMemory() / megabytes;
    if (configuredHeap > requiredHeap) {
        sb.append("<tr><td>Configured Java Heap</td><td>").append(configuredHeap).append(" Megabytes").append("</td></tr>\n");
    } else {
        sb.append("<tr><td>Configured Java Heap</td><td><font color=\"red\">").append(configuredHeap).append("<font color=\"black\">").append(" Megabytes").append("</td></tr>\n");
    }
    sb.append("</table>\n\n");
    // warnings, add warning section if any
    if (warnings.size() > 0) {
        sb.append("<h4>Warnings</h4>");
        sb.append("<table class='table table-condensed'>\n");
        for (Feedback warning : warnings) {
            String procName = warning.getFileName().replace(".class", "");
            String nameLink = "";
            // not a warning during compiling procedures, must from the schema
            if (procName.compareToIgnoreCase("null") == 0) {
                String schemaName = "";
                String warningMsg = warning.getMessage().toLowerCase();
                if (warningMsg.contains("table ")) {
                    int begin = warningMsg.indexOf("table ") + 6;
                    int end = (warningMsg.substring(begin)).indexOf(" ");
                    schemaName = warningMsg.substring(begin, begin + end);
                }
                nameLink = "<a href='#s-" + schemaName + "'>" + schemaName.toUpperCase() + "</a>";
            } else {
                nameLink = "<a href='#p-" + procName.toLowerCase() + "'>" + procName + "</a>";
            }
            sb.append("<tr><td>").append(nameLink).append("</td><td>").append(escapeHtml4(warning.getMessage())).append("</td></tr>\n");
        }
        sb.append("").append("</table>\n").append("</td></tr>\n");
    }
    return sb.toString();
}
Also used : Table(org.voltdb.catalog.Table) Feedback(org.voltdb.compiler.VoltCompiler.Feedback) Procedure(org.voltdb.catalog.Procedure) SimpleDateFormat(java.text.SimpleDateFormat) Constraint(org.voltdb.catalog.Constraint)

Example 2 with Feedback

use of org.voltdb.compiler.VoltCompiler.Feedback in project voltdb by VoltDB.

the class TestVoltCompiler method testInvalidCreateFunctionDDL.

public void testInvalidCreateFunctionDDL() throws Exception {
    ArrayList<Feedback> fbs;
    // Test CREATE FUNCTION syntax
    String[] ddls = new String[] { "CREATE FUNCTION .func FROM METHOD class.method", "CREATE FUNCTION func FROM METHOD class", "CREATE FUNCTION func FROM METHOD .method", "CREATE FUNCTION func FROM METHOD package..class.method", "CREATE FUNCTION func FROM METHOD package.class.method." };
    String expectedError = "Invalid CREATE FUNCTION statement: \"%s\", " + "expected syntax: \"CREATE FUNCTION <name> FROM METHOD <class-name>.<method-name>\"";
    for (String ddl : ddls) {
        fbs = checkInvalidDDL(ddl + ";");
        assertTrue(isFeedbackPresent(String.format(expectedError, ddl), fbs));
    }
    // Test identifiers
    String[][] ddlsAndInvalidIdentifiers = new String[][] { { "CREATE FUNCTION 1nvalid FROM METHOD package.class.method", "1nvalid" }, { "CREATE FUNCTION func FROM METHOD 1nvalid.class.method", "1nvalid.class" }, { "CREATE FUNCTION func FROM METHOD package.1nvalid.method", "package.1nvalid" }, { "CREATE FUNCTION func FROM METHOD package.class.1nvalid", "1nvalid" } };
    expectedError = "Unknown indentifier in DDL: \"%s\" contains invalid identifier \"%s\"";
    for (String[] ddlAndInvalidIdentifier : ddlsAndInvalidIdentifiers) {
        fbs = checkInvalidDDL(ddlAndInvalidIdentifier[0] + ";");
        assertTrue(isFeedbackPresent(String.format(expectedError, ddlAndInvalidIdentifier[0], ddlAndInvalidIdentifier[1]), fbs));
    }
    // Test method validation
    VoltLogger mockedLogger = Mockito.mock(VoltLogger.class);
    VoltCompiler.setVoltLogger(mockedLogger);
    String temporaryWarningMessage = "User-defined functions are not implemented yet.";
    // Class not found
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.NonExistentClass.run;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Cannot load class for user-defined function: org.voltdb.compiler.functions.NonExistentClass", fbs));
    // Abstract class
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.AbstractUDFClass.run;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Cannot define a function using an abstract class org.voltdb.compiler.functions.AbstractUDFClass", fbs));
    // Method not found
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.nonexistent;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Cannot find the implementation method nonexistent for user-defined function afunc in class InvalidUDFLibrary", fbs));
    // Invalid return type
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.runWithUnsupportedReturnType;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Method InvalidUDFLibrary.runWithUnsupportedReturnType has an unsupported return type org.voltdb.compiler.functions.InvalidUDFLibrary$UnsupportedType", fbs));
    // Invalid parameter type
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.runWithUnsupportedParamType;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Method InvalidUDFLibrary.runWithUnsupportedParamType has an unsupported parameter type org.voltdb.compiler.functions.InvalidUDFLibrary$UnsupportedType at position 2", fbs));
    // Multiple functions with the same name
    fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.dup;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Class InvalidUDFLibrary has multiple methods named dup. Only a single function method is supported.", fbs));
    // Function name exists
    // One from FunctionSQL
    fbs = checkInvalidDDL("CREATE FUNCTION abs FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Function \"abs\" is already defined.", fbs));
    // One from FunctionCustom
    fbs = checkInvalidDDL("CREATE FUNCTION log FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Function \"log\" is already defined.", fbs));
    // One from FunctionForVoltDB
    fbs = checkInvalidDDL("CREATE FUNCTION longitude FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    assertTrue(isFeedbackPresent("Function \"longitude\" is already defined.", fbs));
    // The class contains some other invalid functions with the same name
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;", compiler);
    assertTrue("A CREATE FUNCTION statement should be able to succeed, but it did not.", success);
    verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
    verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a non-public run() method."));
    verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a void run() method."));
    verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a static run() method."));
    verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a non-public static void run() method."));
    VoltCompiler.setVoltLogger(new VoltLogger("COMPILER"));
}
Also used : Feedback(org.voltdb.compiler.VoltCompiler.Feedback) VoltLogger(org.voltcore.logging.VoltLogger)

Example 3 with Feedback

use of org.voltdb.compiler.VoltCompiler.Feedback in project voltdb by VoltDB.

the class TestVoltCompiler method testPartitionProcedureWarningMessage.

public void testPartitionProcedureWarningMessage() throws IOException {
    String ddl = "CREATE TABLE PKEY_BIGINT ( PKEY BIGINT NOT NULL, NUM INTEGER, PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_BIGINT ON COLUMN PKEY;" + "create procedure myTestProc as select num from PKEY_BIGINT where pkey = ? order by 1;";
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL(ddl, compiler);
    assertTrue(success);
    String expectedWarning = "This procedure myTestProc would benefit from being partitioned, by adding a " + "'PARTITION ON TABLE PKEY_BIGINT COLUMN PKEY PARAMETER 0' clause to the " + "CREATE PROCEDURE statement. or using a separate PARTITION PROCEDURE statement";
    boolean findMatched = false;
    for (Feedback fb : compiler.m_warnings) {
        System.out.println(fb.getStandardFeedbackLine());
        if (fb.getStandardFeedbackLine().contains(expectedWarning)) {
            findMatched = true;
            break;
        }
    }
    assertTrue(findMatched);
}
Also used : Feedback(org.voltdb.compiler.VoltCompiler.Feedback)

Example 4 with Feedback

use of org.voltdb.compiler.VoltCompiler.Feedback in project voltdb by VoltDB.

the class TestVoltCompiler method testBadDDLErrorLineNumber.

public void testBadDDLErrorLineNumber() throws IOException {
    String schema = // 1
    "-- a comment\n" + // 2
    "create table books (\n" + // 3
    " id integer default 0,\n" + // 4
    " strval varchar(33000) default '',\n" + // 5
    " PRIMARY KEY(id)\n" + // 6
    ");\n" + // 7
    "\n" + // 8
    "-- another comment\n" + // 9 * error reported here *
    "create view badview (\n" + " id,\n" + " COUNT(*),\n" + " total\n" + " as\n" + "select id, COUNT(*), SUM(cnt)\n" + " from books\n" + " group by id;";
    VoltCompiler compiler = new VoltCompiler(false);
    final boolean success = compileDDL(schema, compiler);
    assertFalse(success);
    for (Feedback error : compiler.m_errors) {
        assertEquals(9, error.lineNo);
    }
}
Also used : Feedback(org.voltdb.compiler.VoltCompiler.Feedback)

Example 5 with Feedback

use of org.voltdb.compiler.VoltCompiler.Feedback in project voltdb by VoltDB.

the class TestVoltCompiler method testDropProcedure.

public void testDropProcedure() throws Exception {
    if (Float.parseFloat(System.getProperty("java.specification.version")) < 1.7) {
        return;
    }
    Database db;
    Procedure proc;
    // Make sure we can drop a non-annotated stored procedure
    db = goodDDLAgainstSimpleSchema("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook; " + "DROP PROCEDURE org.voltdb.compiler.procedures.AddBook;");
    proc = db.getProcedures().get("AddBook");
    assertNull(proc);
    proc = db.getProcedures().get("NotAnnotatedAddBook");
    assertNotNull(proc);
    // Make sure we can drop an annotated stored procedure
    db = goodDDLAgainstSimpleSchema("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook; " + "DROP PROCEDURE NotAnnotatedAddBook;");
    proc = db.getProcedures().get("NotAnnotatedAddBook");
    assertNull(proc);
    proc = db.getProcedures().get("AddBook");
    assertNotNull(proc);
    // Make sure we can drop a single-statement procedure
    db = goodDDLAgainstSimpleSchema("create procedure p1 as select * from books;\n" + "drop procedure p1;");
    proc = db.getProcedures().get("p1");
    assertNull(proc);
    ArrayList<Feedback> fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "creAte PrOcEdUrE FrOm CLasS org.voltdb.compiler.procedures.AddBook; " + "DROP PROCEDURE NotAnnotatedAddBook;");
    String expectedError = "Dropped Procedure \"NotAnnotatedAddBook\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // Make sure we can't drop a CRUD procedure (full name)
    fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "DROP PROCEDURE PKEY_INTEGER.insert;");
    expectedError = "Dropped Procedure \"PKEY_INTEGER.insert\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // Make sure we can't drop a CRUD procedure (partial name)
    fbs = checkInvalidDDL("CREATE TABLE PKEY_INTEGER ( PKEY INTEGER NOT NULL, DESCR VARCHAR(128), PRIMARY KEY (PKEY) );" + "PARTITION TABLE PKEY_INTEGER ON COLUMN PKEY;" + "DROP PROCEDURE insert;");
    expectedError = "Dropped Procedure \"insert\" is not defined";
    assertTrue(isFeedbackPresent(expectedError, fbs));
    // check if exists
    db = goodDDLAgainstSimpleSchema("create procedure p1 as select * from books;\n" + "drop procedure p1 if exists;\n" + "drop procedure p1 if exists;\n");
    proc = db.getProcedures().get("p1");
    assertNull(proc);
}
Also used : Feedback(org.voltdb.compiler.VoltCompiler.Feedback) Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure)

Aggregations

Feedback (org.voltdb.compiler.VoltCompiler.Feedback)5 Procedure (org.voltdb.catalog.Procedure)2 SimpleDateFormat (java.text.SimpleDateFormat)1 VoltLogger (org.voltcore.logging.VoltLogger)1 Constraint (org.voltdb.catalog.Constraint)1 Database (org.voltdb.catalog.Database)1 Table (org.voltdb.catalog.Table)1