First version of SQL export
parent
b477728974
commit
336fe2c554
|
@ -14,11 +14,9 @@
|
|||
package org.vizierdb.database;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.vizierdb.database.history.Branch;
|
||||
import org.vizierdb.database.script.Operation;
|
||||
import org.vizierdb.database.script.OperationType;
|
||||
import org.vizierdb.database.script.VizUALScript;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.vizierdb.database.script.VizUALStatement;
|
|||
public class VGEdge {
|
||||
|
||||
private final Operation _operation;
|
||||
private final String _sqlStatement;
|
||||
private final VizUALStatement _stmt;
|
||||
private final VGNode _target;
|
||||
|
||||
|
@ -40,8 +41,9 @@ public class VGEdge {
|
|||
* @param target
|
||||
* @param operation
|
||||
* @param stmt
|
||||
* @param sqlStatement
|
||||
*/
|
||||
public VGEdge(VGNode target, Operation operation, VizUALStatement stmt) {
|
||||
public VGEdge(VGNode target, Operation operation, VizUALStatement stmt, String sqlStatement) {
|
||||
|
||||
if (operation == null) {
|
||||
throw new java.lang.IllegalArgumentException("Derivation operation: null");
|
||||
|
@ -50,6 +52,7 @@ public class VGEdge {
|
|||
_target = target;
|
||||
_operation = operation;
|
||||
_stmt = stmt;
|
||||
_sqlStatement = sqlStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,10 +60,11 @@ public class VGEdge {
|
|||
*
|
||||
* @param operation
|
||||
* @param stmt
|
||||
* @param sqlStatement
|
||||
*/
|
||||
public VGEdge(Operation operation, VizUALStatement stmt) {
|
||||
public VGEdge(Operation operation, VizUALStatement stmt, String sqlStatement) {
|
||||
|
||||
this(null, operation, stmt);
|
||||
this(null, operation, stmt, sqlStatement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,11 +83,16 @@ public class VGEdge {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public VizUALStatement getStatement() {
|
||||
public VizUALStatement getVizUALStatement() {
|
||||
|
||||
return _stmt;
|
||||
}
|
||||
|
||||
public String getSQLStatement() {
|
||||
|
||||
return _sqlStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Node representing the target snapshot.
|
||||
*
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.vizierdb.database.Snapshot;
|
|||
import org.vizierdb.database.script.Operation;
|
||||
import org.vizierdb.database.script.VizUALScript;
|
||||
import org.vizierdb.database.VizierDB;
|
||||
import org.vizierdb.database.script.op.CSVFileLoad;
|
||||
|
||||
/**
|
||||
* The version graph maintains information how snapshots in a notebook's
|
||||
|
@ -38,6 +39,7 @@ public class VersionGraph {
|
|||
private Branch _currentBranch;
|
||||
private final HashMap<Integer, VGNode> _nodes;
|
||||
private VGNode _root;
|
||||
private String _tableName = null;
|
||||
|
||||
/**
|
||||
* Create an empty graph. HEAD and ROOT are undefined for an empty graph.
|
||||
|
@ -92,7 +94,16 @@ public class VersionGraph {
|
|||
if (_root != null) {
|
||||
throw new java.lang.IllegalStateException("Version graph root has been set");
|
||||
}
|
||||
_root = new VGNode(targetId, new VGEdge(operation, operation.getStatement(source)));
|
||||
/**
|
||||
* NOTE: This is a hack. requires the first operation to be a load
|
||||
* operation. Should be changed.
|
||||
*/
|
||||
_tableName = ((CSVFileLoad)operation).getFileName();
|
||||
int pos = _tableName.indexOf(".");
|
||||
if (pos != -1) {
|
||||
_tableName = _tableName.substring(0, pos);
|
||||
}
|
||||
_root = new VGNode(targetId, new VGEdge(operation, operation.getVizUALStatement(source), operation.getSQLStatement(source, _tableName)));
|
||||
_nodes.put(targetId, _root);
|
||||
_currentBranch.setHead(targetId);
|
||||
return _root;
|
||||
|
@ -104,7 +115,7 @@ public class VersionGraph {
|
|||
if (parent == null) {
|
||||
throw new java.lang.IllegalArgumentException("Unknown snapshot: " + sourceId);
|
||||
}
|
||||
VGNode node = new VGNode(targetId, new VGEdge(parent, operation, operation.getStatement(source)));
|
||||
VGNode node = new VGNode(targetId, new VGEdge(parent, operation, operation.getVizUALStatement(source), operation.getSQLStatement(source, _tableName)));
|
||||
_nodes.put(targetId, node);
|
||||
/**
|
||||
* If the source snapshot is head of a branch then we will extend that
|
||||
|
@ -225,11 +236,11 @@ public class VersionGraph {
|
|||
VGNode node = _nodes.get(branch.getHead());
|
||||
if (node != null) {
|
||||
VGEdge derivation = node.getParent();
|
||||
script.addAtBeginning(derivation.getOperation(), derivation.getStatement(), node.getSnapshotIdentifier());
|
||||
script.addAtBeginning(derivation.getOperation(), derivation.getVizUALStatement(), derivation.getSQLStatement(), node.getSnapshotIdentifier());
|
||||
while (derivation.hasTarget()) {
|
||||
node = derivation.getTarget();
|
||||
derivation = node.getParent();
|
||||
script.addAtBeginning(derivation.getOperation(), derivation.getStatement(), node.getSnapshotIdentifier());
|
||||
script.addAtBeginning(derivation.getOperation(), derivation.getVizUALStatement(), derivation.getSQLStatement(), node.getSnapshotIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,16 @@ public abstract class Operation {
|
|||
* @param snapshot
|
||||
* @return
|
||||
*/
|
||||
public abstract VizUALStatement getStatement(Snapshot snapshot);
|
||||
public abstract VizUALStatement getVizUALStatement(Snapshot snapshot);
|
||||
|
||||
/**
|
||||
* SQL statement representing the operation when applied to the given
|
||||
* snapshot.
|
||||
*
|
||||
* @param snapshot
|
||||
* @return
|
||||
*/
|
||||
public abstract String getSQLStatement(Snapshot snapshot, String tableName);
|
||||
|
||||
/**
|
||||
* Operation type.
|
||||
|
|
|
@ -28,12 +28,14 @@ public class VizUALScript {
|
|||
|
||||
public final Operation op;
|
||||
public final int snapshot;
|
||||
public final String sqlStmt;
|
||||
public final VizUALStatement stmt;
|
||||
|
||||
public ScriptOp(Operation op, VizUALStatement stmt, int snapshot) {
|
||||
public ScriptOp(Operation op, VizUALStatement stmt, String sqlStmt, int snapshot) {
|
||||
|
||||
this.op = op;
|
||||
this.stmt = stmt;
|
||||
this.sqlStmt = sqlStmt;
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +47,12 @@ public class VizUALScript {
|
|||
*
|
||||
* @param operation
|
||||
* @param stmt
|
||||
* @param sqlStmt
|
||||
* @param snapshotIdentifier
|
||||
*/
|
||||
public void addAtBeginning(Operation operation, VizUALStatement stmt, int snapshotIdentifier) {
|
||||
public void addAtBeginning(Operation operation, VizUALStatement stmt, String sqlStmt, int snapshotIdentifier) {
|
||||
|
||||
_ops.addFirst(new ScriptOp(operation, stmt, snapshotIdentifier));
|
||||
_ops.addFirst(new ScriptOp(operation, stmt, sqlStmt, snapshotIdentifier));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,11 +60,12 @@ public class VizUALScript {
|
|||
*
|
||||
* @param operation
|
||||
* @param stmt
|
||||
* @param sqlStmt
|
||||
* @param snapshotIdentifier
|
||||
*/
|
||||
public void addAtEnd(Operation operation, VizUALStatement stmt, int snapshotIdentifier) {
|
||||
public void addAtEnd(Operation operation, VizUALStatement stmt, String sqlStmt, int snapshotIdentifier) {
|
||||
|
||||
_ops.add(new ScriptOp(operation, stmt, snapshotIdentifier));
|
||||
_ops.add(new ScriptOp(operation, stmt, sqlStmt, snapshotIdentifier));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,11 +115,16 @@ public class VizUALScript {
|
|||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public VizUALStatement getStatement(int index) {
|
||||
public VizUALStatement getVizUALStatement(int index) {
|
||||
|
||||
return _ops.get(index).stmt;
|
||||
}
|
||||
|
||||
public String getSQLStatement(int index) {
|
||||
|
||||
return _ops.get(index).sqlStmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of operations in the script.
|
||||
*
|
||||
|
|
|
@ -56,11 +56,11 @@ public class VizualTranslator implements Serializable {
|
|||
return getVizQL(vizualLine);
|
||||
}
|
||||
|
||||
private void setTableName(String tableName) {
|
||||
public void setTableName(String tableName) {
|
||||
VizualTranslator.tableName = tableName;
|
||||
}
|
||||
|
||||
private String getVizQL(String line) throws ParseException {
|
||||
public String getVizQL(String line) throws ParseException {
|
||||
String firstWord;
|
||||
String constructedSQL;
|
||||
String[] tokens;
|
||||
|
@ -139,7 +139,7 @@ public class VizualTranslator implements Serializable {
|
|||
return constructedSQL;
|
||||
}
|
||||
|
||||
private class ParseException extends Exception implements Serializable {
|
||||
public class ParseException extends Exception implements Serializable {
|
||||
ParseException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class CSVFileLoad extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String cmd = "LOAD FILE " + _fileName + " OF TYPE " + _formatName;
|
||||
String html = "<span class=\"cmd-txt\">LOAD FILE</span> <span class=\"cmd-para\">" + _fileName + "</span>";
|
||||
|
@ -214,6 +214,12 @@ public class CSVFileLoad extends Operation {
|
|||
return new VizUALStatement(cmd, html, "LOAD FILE " + _fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "CREATE TABLE " + tableName + " AS SELECT *, ROWID AS VIZIER_ROWID " + "FROM " + _fileName + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ public class CellUpdate extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String cellReference;
|
||||
String cellReferenceHtml;
|
||||
|
@ -321,6 +321,13 @@ public class CellUpdate extends Operation {
|
|||
return new VizUALStatement(cmd, html, shortCmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "UPDATE TABLE " + tableName + " SET " + snapshot.getColumns().getColumn(_columnId).getDescriptiveName() + " = '" + _value
|
||||
+ "' WHERE VIZIER_ROWID = " + _rowId + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ColumnDelete extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String name = snapshot.getColumns().getColumn(_columnId).getDescriptiveName();
|
||||
String cmd = "DELETE COLUMN " + name;
|
||||
|
@ -119,6 +119,12 @@ public class ColumnDelete extends Operation {
|
|||
return new VizUALStatement(cmd, html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "ALTER TABLE " + tableName + " DROP COLUMN " + snapshot.getColumns().getColumn(_columnId).getDescriptiveName() + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ public class ColumnInsert extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String cmd = "INSERT COLUMN " + _name + " AT POSITION " + _position;
|
||||
String html = "<span class=\"cmd-txt\">INSERT COLUMN <span class=\"cmd-para\">" + _name + "</span> AT POSITION <span class=\"cmd-para\">" + _position + "</span>";
|
||||
|
@ -137,6 +137,12 @@ public class ColumnInsert extends Operation {
|
|||
return new VizUALStatement(cmd, html, "INSERT COLUMN " + _name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "ALTER TABLE " + tableName + " ADD COLUMN " + _name + " CHAR(100);";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ public class ColumnMove extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String columnName = snapshot.getColumns().getColumn(_columnId).getDescriptiveName();
|
||||
String cmd = "MOVE COLUMN " + columnName + " TO POSITION " + _position;
|
||||
|
@ -151,6 +151,11 @@ public class ColumnMove extends Operation {
|
|||
return new VizUALStatement(cmd, html, "MOVE COLUMN " + columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
return "UNDEFINED: MOVE COLUMN";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ColumnRename extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String columnName = snapshot.getColumns().getColumn(_columnId).getDescriptiveName();
|
||||
String cmd = "RENAME COLUMN " + columnName + " AS " + _name;
|
||||
|
@ -120,6 +120,12 @@ public class ColumnRename extends Operation {
|
|||
return new VizUALStatement(cmd, html, "RENAME COLUMN " + columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "ALTER TABLE " + tableName + " RENAME COLUMN " + snapshot.getColumns().getColumn(_columnId).getDescriptiveName() + " TO " + _name + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ public class RowDelete extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String rowName = snapshot.getRows().getDescriptiveName(_rowId);
|
||||
String cmd = "DELETE ROW " + rowName;
|
||||
|
@ -122,6 +122,12 @@ public class RowDelete extends Operation {
|
|||
return new VizUALStatement(cmd, html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
return "DELETE FROM " + tableName + " WHERE VIZIER_ROWID = " + _rowId + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -73,7 +73,12 @@ public class RowFilter extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.vizierdb.database.script.op;
|
|||
|
||||
import java.util.HashMap;
|
||||
import org.vizierdb.RequestParameterException;
|
||||
import org.vizierdb.database.Column;
|
||||
import org.vizierdb.database.Notebook;
|
||||
import org.vizierdb.database.RowList;
|
||||
import org.vizierdb.database.Snapshot;
|
||||
|
@ -95,7 +96,7 @@ public class RowInsert extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String cmd = "INSERT ROW AT POSITION " + _position;
|
||||
String html = "<span class=\"cmd-txt\">INSERT ROW</span> AT POSITION <span class=\"cmd-para\">" + _position + "</span>";
|
||||
|
@ -103,6 +104,18 @@ public class RowInsert extends Operation {
|
|||
return new VizUALStatement(cmd, html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
|
||||
String columnList = "VIZIER_ROWID";
|
||||
String valueList = Integer.toString(snapshot.getRows().size());
|
||||
for (Column column : snapshot.getColumns()) {
|
||||
columnList = columnList + ", " + column.getDescriptiveName();
|
||||
valueList = valueList + ", ''";
|
||||
}
|
||||
return "INSERT INTO " + tableName + "(" + columnList + ") VALUES(" + valueList + ");";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ public class RowMove extends Operation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VizUALStatement getStatement(Snapshot snapshot) {
|
||||
public VizUALStatement getVizUALStatement(Snapshot snapshot) {
|
||||
|
||||
String rowName = snapshot.getRows().getDescriptiveName(_rowId);
|
||||
String cmd = "MOVE ROW " + rowName + " TO POSITION " + _position;
|
||||
|
@ -147,6 +147,11 @@ public class RowMove extends Operation {
|
|||
return new VizUALStatement(cmd, html, "MOVE ROW " + rowName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLStatement(Snapshot snapshot, String tableName) {
|
||||
return "UNDEFINED: MOVE ROW";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Snapshot snapshot) {
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.vizierdb.database.VizierDB;
|
|||
import org.vizierdb.database.script.Operation;
|
||||
import org.vizierdb.resources.ResourceManager;
|
||||
import org.vizierdb.server.io.FileListingStream;
|
||||
import org.vizierdb.server.io.ScriptSQLStatementStream;
|
||||
|
||||
/**
|
||||
* The Vizier Database Web API Server.
|
||||
|
@ -72,12 +73,12 @@ public class DatabaseServer {
|
|||
/*
|
||||
* Uncomment for local web server
|
||||
*/
|
||||
_urls = new URLFactory("http://localhost:8080/vizier-db/api/v1");
|
||||
//_urls = new URLFactory("http://localhost:8080/vizier-db/api/v1");
|
||||
|
||||
/*
|
||||
* Uncomment for current AWS deployment
|
||||
*/
|
||||
//_urls = new URLFactory("http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com/api/v1");
|
||||
_urls = new URLFactory("http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com/api/v1");
|
||||
|
||||
_resources = new ResourceManager(new File(context.getRealPath("/WEB-INF/resources")));
|
||||
_vdb = new SimpleVizierDBM(_resources);
|
||||
|
@ -295,6 +296,34 @@ public class DatabaseServer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VizUAL script associated with a given branch as an array of
|
||||
* SQL statements.
|
||||
*
|
||||
* @param notebookIdentifier Notebook identifier
|
||||
* @param branchIdentifier Branch identifier
|
||||
* @return
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Path("/notebooks/{notebookIdentifier}/branches/{branchIdentifier}/script/sql")
|
||||
@GET
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response getBranchScriptSQLExport(@PathParam("notebookIdentifier") int notebookIdentifier, @PathParam("branchIdentifier") int branchIdentifier) throws java.io.IOException, javax.ws.rs.WebApplicationException {
|
||||
|
||||
VizUALScript script = null;
|
||||
try {
|
||||
script = _vdb.getScript(notebookIdentifier, branchIdentifier);
|
||||
} catch (org.vizierdb.VizirDBException vizierException ){
|
||||
Logger.getLogger(DatabaseServer.class.getName()).log(Level.SEVERE, null, vizierException);
|
||||
throw new WebApplicationException(500);
|
||||
}
|
||||
if (script != null) {
|
||||
return Response.ok().entity(new ScriptSQLStatementStream(script)).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
throw new WebApplicationException(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an operation on the head of the given branch.
|
||||
*
|
||||
|
|
|
@ -44,6 +44,19 @@ public class URLFactory {
|
|||
return this.getNotebookBranchURL(notebookIdentifier, branchIdentifier) + "/script";
|
||||
}
|
||||
|
||||
/**
|
||||
* URL referencing SQL translation of the script resource for a branch in a
|
||||
* notebook.
|
||||
*
|
||||
* @param notebookIdentifier Notebook identifier
|
||||
* @param branchIdentifier Branch identifier
|
||||
* @return
|
||||
*/
|
||||
public String getBranchScriptSQLExportURL(int notebookIdentifier, int branchIdentifier) {
|
||||
|
||||
return this.getNotebookBranchURL(notebookIdentifier, branchIdentifier) + "/script/sql";
|
||||
}
|
||||
|
||||
/**
|
||||
* URL referencing script resource for a branch in a notebook.
|
||||
*
|
||||
|
|
|
@ -292,9 +292,9 @@ public class ResourceStreamWriter implements AutoCloseable {
|
|||
_out.endObject();
|
||||
VGEdge edge = node.getParent();
|
||||
if (edge.hasTarget()) {
|
||||
edges.add(new Edge(edge.getTarget().getSnapshotIdentifier(), edge.getStatement(), node.getSnapshotIdentifier()));
|
||||
edges.add(new Edge(edge.getTarget().getSnapshotIdentifier(), edge.getVizUALStatement(), node.getSnapshotIdentifier()));
|
||||
} else {
|
||||
edges.add(new Edge(VizierDB.UNKNOWN_SNAPSHOT, edge.getStatement(), node.getSnapshotIdentifier()));
|
||||
edges.add(new Edge(VizierDB.UNKNOWN_SNAPSHOT, edge.getVizUALStatement(), node.getSnapshotIdentifier()));
|
||||
}
|
||||
}
|
||||
_out.endArray();
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.vizierdb.server.io;
|
|||
import java.io.OutputStream;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import org.vizierdb.database.script.VizUALScript;
|
||||
import org.vizierdb.server.ReferenceObject;
|
||||
import org.vizierdb.server.URLFactory;
|
||||
|
||||
/**
|
||||
|
@ -45,9 +46,12 @@ public class ScriptObjectStream implements StreamingOutput {
|
|||
writer.getWriter().beginObject();
|
||||
writer.getWriter().name("operations").beginArray();
|
||||
for (int iOp = 0; iOp < _script.size(); iOp++) {
|
||||
writer.writeOperation(_script.getStatement(iOp), _notebookIdentifier, _branchIdentifier, _script.getSnapshotIdentifier(iOp), _urls);
|
||||
writer.writeOperation(_script.getVizUALStatement(iOp), _notebookIdentifier, _branchIdentifier, _script.getSnapshotIdentifier(iOp), _urls);
|
||||
}
|
||||
writer.getWriter().endArray();
|
||||
writer.getWriter().name("links").beginArray();
|
||||
writer.writeReference(new ReferenceObject("sql", _urls.getBranchScriptSQLExportURL(_notebookIdentifier, _branchIdentifier)));
|
||||
writer.getWriter().endArray();
|
||||
writer.getWriter().endObject();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.vizierdb.server.io;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import org.vizierdb.database.script.VizUALScript;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author heiko
|
||||
*/
|
||||
public class ScriptSQLStatementStream implements StreamingOutput{
|
||||
|
||||
private final VizUALScript _script;
|
||||
|
||||
public ScriptSQLStatementStream(VizUALScript script) {
|
||||
|
||||
_script = script;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) throws java.io.IOException, javax.ws.rs.WebApplicationException {
|
||||
|
||||
try (ResourceStreamWriter writer = new ResourceStreamWriter(out)) {
|
||||
writer.getWriter().beginObject();
|
||||
writer.getWriter().name("operations").beginArray();
|
||||
for (int iOp = 0; iOp < _script.size(); iOp++) {
|
||||
writer.getWriter().beginObject();
|
||||
writer.getWriter().name("sql").value(_script.getSQLStatement(iOp));
|
||||
writer.getWriter().endObject();
|
||||
}
|
||||
writer.getWriter().endArray();
|
||||
writer.getWriter().endObject();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,11 @@ p.panel-subheadline {
|
|||
color: #333;
|
||||
}
|
||||
|
||||
p.sql-statement {
|
||||
font-weight: bold;
|
||||
color: #00313C;
|
||||
}
|
||||
|
||||
/*
|
||||
* Panels
|
||||
*/
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
if (url && url.length > 1) {
|
||||
url = decodeURIComponent(url[1]);
|
||||
} else {
|
||||
url = "http://localhost:8080/vizier-db/doc/vizier-db.yaml";
|
||||
//url = "http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com/doc/vizier-db.yaml";
|
||||
//url = "http://localhost:8080/vizier-db/doc/vizier-db.yaml";
|
||||
url = "http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com/doc/vizier-db.yaml";
|
||||
}
|
||||
|
||||
hljs.configure({
|
||||
|
|
|
@ -11,8 +11,8 @@ info:
|
|||
|
||||
schemes:
|
||||
- http
|
||||
#host: vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com
|
||||
host: localhost:8080/vizier-db
|
||||
host: vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com
|
||||
#host: localhost:8080/vizier-db
|
||||
basePath: /api/v1
|
||||
|
||||
paths:
|
||||
|
@ -239,7 +239,10 @@ paths:
|
|||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/VizUALOperation"
|
||||
|
||||
links:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/Reference"
|
||||
404:
|
||||
description: Notebook not found
|
||||
post:
|
||||
|
@ -282,6 +285,45 @@ paths:
|
|||
description: Invalid parameters
|
||||
404:
|
||||
description: Notebook or branch not found
|
||||
/notebooks/{notebookIdentifier}/branches/{branchIdentifier}/script/sql:
|
||||
get:
|
||||
summary: Get VizUAL script as SQL
|
||||
description: List the sequence of operations in the VizUAL script
|
||||
representing the curation workflow that represented by the
|
||||
branch as SQL statements
|
||||
operationId: getBranchScriptSQLExport
|
||||
tags:
|
||||
- branch
|
||||
- script
|
||||
parameters:
|
||||
- name: notebookIdentifier
|
||||
in: path
|
||||
required: true
|
||||
description: The unique notbook identifier
|
||||
type: integer
|
||||
format: int32
|
||||
- name: branchIdentifier
|
||||
in: path
|
||||
required: true
|
||||
description: The brnach identifier
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
200:
|
||||
description: List of operations in curation workflow as SQL
|
||||
statements
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
operations:
|
||||
type: array
|
||||
items:
|
||||
properties:
|
||||
sql:
|
||||
type: string
|
||||
|
||||
404:
|
||||
description: Notebook not found
|
||||
/notebooks/{notebookIdentifier}/branches/{branchIdentifier}/script/snapshots/{snapshotIdentifier}:
|
||||
delete:
|
||||
summary: Delete snapshot from branch
|
||||
|
|
|
@ -291,5 +291,22 @@
|
|||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- SHOW SQL -->
|
||||
<div class="modal fade" id="modal-show-sql" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">VizUAL Script - SQL Translation</h4>
|
||||
</div>
|
||||
<div class="modal-body" id="modal-show-sql-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
</body></html>
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
*
|
||||
* @type String
|
||||
*/
|
||||
//var apiUrl = 'http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com//api/v1';
|
||||
var apiUrl = 'http://localhost:8080/vizier-db/api/v1';
|
||||
var apiUrl = 'http://vizirdb.7mi5uspdsy.us-west-2.elasticbeanstalk.com//api/v1';
|
||||
//var apiUrl = 'http://localhost:8080/vizier-db/api/v1';
|
||||
|
||||
/**
|
||||
* Maintains global variables for the current notebook
|
||||
|
@ -397,6 +397,7 @@ function showNotebook(href) {
|
|||
'<button class="btn btn-invert btn-sm toggle-dropdown disabled" id="script-dropdown-btn" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true"> <span class="glyphicon glyphicon-cog"></span></button>' +
|
||||
'<ul class="dropdown-menu dropdown-menu-right">' +
|
||||
'<li><a href="#" onclick="deleteSnapshot();"><span class="glyphicon glyphicon-trash"></span> Delete Operation</a></li>' +
|
||||
'<li><a href="#" onclick="showSQL();"><span class="glyphicon glyphicon-export"></span> Export as SQL</a></li>' +
|
||||
'</ul>' +
|
||||
'</div>';
|
||||
// Put it all together
|
||||
|
@ -605,6 +606,24 @@ function showVersionGraph(url, head) {
|
|||
});
|
||||
}
|
||||
|
||||
function showSQL() {
|
||||
|
||||
var url = getReference('sql', notebook.script.links);
|
||||
if (url) {
|
||||
$.get(url, function(data, status) {
|
||||
if (status === 'success') {
|
||||
var innerHtml = '<div class="sql-statement">';
|
||||
for (var iOp = 0; iOp < data.operations.length; iOp++) {
|
||||
innerHtml += '<p class="sql-statement">' + data.operations[iOp].sql + '</p>';
|
||||
}
|
||||
innerHtml += '</div>';
|
||||
$("#modal-show-sql-body").html(innerHtml);
|
||||
$('#modal-show-sql').modal('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Modify Spreadsheety (UPDATE CELL)
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ConstructSQL {
|
|||
schemas.put("simple", Arrays.asList("Name","Age","Department"));
|
||||
|
||||
try {
|
||||
SimpleVizierDBM vdb = new SimpleVizierDBM(new ResourceManager(new File("/Users/okennedy/Documents/Mimir/Vizier/src/main/webapp/WEB-INF/resources")));
|
||||
SimpleVizierDBM vdb = new SimpleVizierDBM(new ResourceManager(new File("/home/heiko/work/src/curation/vizir/vizier-db/src/main/webapp/WEB-INF/resources")));
|
||||
Notebook nb = vdb.createNotebook("My Notebook");
|
||||
// 0 - LoadFile
|
||||
op = new JsonParser().parse("{\"type\":\"LoadFile\", \"parameters\": [{\"name\" : \"file\", \"value\" : \"simple.csv\"}, {\"name\" : \"format\", \"value\" : \"RFC4180\"}, {\"name\" : \"headline\", \"value\" : \"true\"}]}").getAsJsonObject();
|
||||
|
|
Loading…
Reference in New Issue