Search in sources :

Example 21 with Database

use of org.voltdb.catalog.Database in project voltdb by VoltDB.

the class GenerateEETests method generatedRankPlan.

public void generatedRankPlan() throws Exception {
    Database db = getDatabase();
    TableConfig rankInput = makeRankInput(db);
    TableConfig rankOutput = makeRankOutput(db);
    TableConfig rankDenseOutput = makeRankDenseOutput(db);
    DBConfig rankDB = new DBConfig(getClass(), GenerateEETests.class.getResource(DDL_FILENAME), getCatalogString(), rankInput, rankOutput, rankDenseOutput);
    String sqlStmt;
    sqlStmt = "select A, B, C, rank() over (partition by A order by B) as R from T ORDER BY A, B, C, R;";
    rankDB.addTest(new TestConfig("test_rank", sqlStmt, false, rankOutput));
    sqlStmt = "select A, B, C, dense_rank() over (partition by A order by B) as R from T ORDER BY A, B, C, R;";
    rankDB.addTest(new TestConfig("test_dense_rank", sqlStmt, false, rankDenseOutput));
    generateTests("executors", "TestWindowedRank", rankDB);
}
Also used : Database(org.voltdb.catalog.Database)

Example 22 with Database

use of org.voltdb.catalog.Database in project voltdb by VoltDB.

the class VoltCompiler method compileDatabaseNode.

/**
     * Load a ddl file with full support for VoltDB extensions (partitioning, procedures,
     * export), AND full support for input via a project xml file's "database" node.
     * @param database catalog-related info parsed from a project file
     * @param ddlReaderList Reader objects for ddl files.
     * @param jarOutput The in-memory jar to populate or null if the caller doesn't provide one.
     * @throws VoltCompilerException
     */
private void compileDatabaseNode(VoltCompilerReader cannonicalDDLIfAny, Database previousDBIfAny, final List<VoltCompilerReader> ddlReaderList, final InMemoryJarfile jarOutput) throws VoltCompilerException {
    final ArrayList<Class<?>> classDependencies = new ArrayList<>();
    final VoltDDLElementTracker voltDdlTracker = new VoltDDLElementTracker(this);
    Database db = initCatalogDatabase(m_catalog);
    // shutdown and make a new hsqldb
    HSQLInterface hsql = HSQLInterface.loadHsqldb();
    compileDatabase(db, hsql, voltDdlTracker, cannonicalDDLIfAny, previousDBIfAny, ddlReaderList, classDependencies, DdlProceduresToLoad.ALL_DDL_PROCEDURES, jarOutput);
}
Also used : HSQLInterface(org.hsqldb_voltpatches.HSQLInterface) ArrayList(java.util.ArrayList) Database(org.voltdb.catalog.Database)

Example 23 with Database

use of org.voltdb.catalog.Database in project voltdb by VoltDB.

the class VoltCompiler method compileInternal.

/**
     * Internal method for compiling with and without a project.xml file or DDL files.
     *
     * @param projectReader Reader for project file or null if a project file is not used.
     * @param ddlFilePaths The list of DDL files to compile (when no project is provided).
     * @param jarOutputRet The in-memory jar to populate or null if the caller doesn't provide one.
     * @return The InMemoryJarfile containing the compiled catalog if
     * successful, null if not.  If the caller provided an InMemoryJarfile, the
     * return value will be the same object, not a copy.
     */
private InMemoryJarfile compileInternal(final VoltCompilerReader cannonicalDDLIfAny, final Catalog previousCatalogIfAny, final List<VoltCompilerReader> ddlReaderList, final InMemoryJarfile jarOutputRet) {
    // Expect to have either >1 ddl file or a project file.
    assert (ddlReaderList.size() > 0);
    // Make a temporary local output jar if one wasn't provided.
    final InMemoryJarfile jarOutput = (jarOutputRet != null ? jarOutputRet : new InMemoryJarfile());
    if (ddlReaderList == null || ddlReaderList.isEmpty()) {
        addErr("One or more DDL files are required.");
        return null;
    }
    // clear out the warnings and errors
    m_warnings.clear();
    m_infos.clear();
    m_errors.clear();
    // do all the work to get the catalog
    final Catalog catalog = compileCatalogInternal(cannonicalDDLIfAny, previousCatalogIfAny, ddlReaderList, jarOutput);
    if (catalog == null) {
        return null;
    }
    Cluster cluster = catalog.getClusters().get("cluster");
    assert (cluster != null);
    Database database = cluster.getDatabases().get("database");
    assert (database != null);
    // Build DDL from Catalog Data
    String ddlWithBatchSupport = CatalogSchemaTools.toSchema(catalog, m_importLines);
    m_canonicalDDL = CatalogSchemaTools.toSchemaWithoutInlineBatches(ddlWithBatchSupport);
    // generate the catalog report and write it to disk
    try {
        generateCatalogReport(ddlWithBatchSupport);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    jarOutput.put(AUTOGEN_DDL_FILE_NAME, m_canonicalDDL.getBytes(Constants.UTF8ENCODING));
    if (DEBUG_VERIFY_CATALOG) {
        debugVerifyCatalog(jarOutput, catalog);
    }
    // WRITE CATALOG TO JAR HERE
    final String catalogCommands = catalog.serialize();
    byte[] catalogBytes = catalogCommands.getBytes(Constants.UTF8ENCODING);
    try {
        // Note when upgrading the version has already been updated by the caller.
        if (!jarOutput.containsKey(CatalogUtil.CATALOG_BUILDINFO_FILENAME)) {
            addBuildInfo(jarOutput);
        }
        jarOutput.put(CatalogUtil.CATALOG_FILENAME, catalogBytes);
        // put the compiler report into the jarfile
        jarOutput.put("catalog-report.html", m_report.getBytes(Constants.UTF8ENCODING));
    } catch (final Exception e) {
        e.printStackTrace();
        return null;
    }
    assert (!hasErrors());
    if (hasErrors()) {
        return null;
    }
    return jarOutput;
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Database(org.voltdb.catalog.Database) Cluster(org.voltdb.catalog.Cluster) IOException(java.io.IOException) Catalog(org.voltdb.catalog.Catalog) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Example 24 with Database

use of org.voltdb.catalog.Database in project voltdb by VoltDB.

the class VoltCompiler method loadSchema.

/**
     * Simplified interface for loading a ddl file with full support for VoltDB
     * extensions (partitioning, procedures, export), but no support for "project file" input.
     * This is, at least initially, only a back door to create a fully functional catalog for
     * the purposes of planner unit testing.
     * @param hsql an interface to the hsql frontend, initialized and potentially reused by the caller.
     * @param whichProcs indicates which ddl-defined procedures to load: none, single-statement, or all
     * @param ddlFilePaths schema file paths
     * @throws VoltCompilerException
     */
public Catalog loadSchema(HSQLInterface hsql, DdlProceduresToLoad whichProcs, String... ddlFilePaths) throws VoltCompilerException {
    //
    m_catalog = new Catalog();
    m_catalog.execute("add / clusters cluster");
    Database db = initCatalogDatabase(m_catalog);
    List<VoltCompilerReader> ddlReaderList = DDLPathsToReaderList(ddlFilePaths);
    final VoltDDLElementTracker voltDdlTracker = new VoltDDLElementTracker(this);
    InMemoryJarfile jarOutput = new InMemoryJarfile();
    compileDatabase(db, hsql, voltDdlTracker, null, null, ddlReaderList, null, whichProcs, jarOutput);
    return m_catalog;
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Database(org.voltdb.catalog.Database) Catalog(org.voltdb.catalog.Catalog)

Example 25 with Database

use of org.voltdb.catalog.Database in project voltdb by VoltDB.

the class VoltCompiler method compileCatalogInternal.

/**
     * Internal method for compiling the catalog.
     *
     * @param database catalog-related info parsed from a project file
     * @param ddlReaderList Reader objects for ddl files.
     * @param jarOutput The in-memory jar to populate or null if the caller doesn't provide one.
     * @return true if successful
     */
private Catalog compileCatalogInternal(final VoltCompilerReader cannonicalDDLIfAny, final Catalog previousCatalogIfAny, final List<VoltCompilerReader> ddlReaderList, final InMemoryJarfile jarOutput) {
    m_catalog = new Catalog();
    // Initialize the catalog for one cluster
    m_catalog.execute("add / clusters cluster");
    m_catalog.getClusters().get("cluster").setSecurityenabled(false);
    // shutdown and make a new hsqldb
    try {
        Database previousDBIfAny = null;
        if (previousCatalogIfAny != null) {
            previousDBIfAny = previousCatalogIfAny.getClusters().get("cluster").getDatabases().get("database");
        }
        compileDatabaseNode(cannonicalDDLIfAny, previousDBIfAny, ddlReaderList, jarOutput);
    } catch (final VoltCompilerException e) {
        return null;
    }
    assert (m_catalog != null);
    // add epoch info to catalog
    final int epoch = (int) (TransactionIdManager.getEpoch() / 1000);
    m_catalog.getClusters().get("cluster").setLocalepoch(epoch);
    return m_catalog;
}
Also used : Database(org.voltdb.catalog.Database) Catalog(org.voltdb.catalog.Catalog)

Aggregations

Database (org.voltdb.catalog.Database)62 Table (org.voltdb.catalog.Table)22 Catalog (org.voltdb.catalog.Catalog)12 Cluster (org.voltdb.catalog.Cluster)10 File (java.io.File)9 Column (org.voltdb.catalog.Column)9 Procedure (org.voltdb.catalog.Procedure)9 IOException (java.io.IOException)5 VoltTable (org.voltdb.VoltTable)5 ArrayList (java.util.ArrayList)4 Group (org.voltdb.catalog.Group)4 Connector (org.voltdb.catalog.Connector)3 Constraint (org.voltdb.catalog.Constraint)3 Statement (org.voltdb.catalog.Statement)3 FileNotFoundException (java.io.FileNotFoundException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 JAXBException (javax.xml.bind.JAXBException)2