Skip to content

Commit

Permalink
added REST support and encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
jortiz16 committed May 15, 2016
1 parent ea8f505 commit 8de5eb8
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 14 deletions.
57 changes: 57 additions & 0 deletions src/edu/washington/escience/myria/api/DatasetResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.TupleWriter;
import edu.washington.escience.myria.accessmethod.AccessMethod.IndexRef;
import edu.washington.escience.myria.api.encoding.CreateIndexEncoding;
import edu.washington.escience.myria.api.encoding.CreateUDFEncoding;
import edu.washington.escience.myria.api.encoding.CreateViewEncoding;
import edu.washington.escience.myria.api.encoding.DatasetEncoding;
import edu.washington.escience.myria.api.encoding.DatasetStatus;
import edu.washington.escience.myria.api.encoding.TipsyDatasetEncoding;
Expand Down Expand Up @@ -374,6 +377,60 @@ public Response persistDataset(@PathParam("userName") final String userName,
return response.entity(queryId).build();
}

/**
* Creates an index based on the DbCreateIndexEncoding
*/
@POST
@Path("/createIndex/")
@Consumes(MediaType.APPLICATION_JSON)
public Response createIndex(final CreateIndexEncoding encoding) throws DbException {
long queryId;
try {
queryId = server.addIndexesToRelation(encoding.relationKey, encoding.schema, encoding.indexes);
} catch (Exception e) {
throw new DbException();
}
/* Build the response to return the queryId */
ResponseBuilder response = Response.ok();
return response.entity(queryId).build();
}

/**
* Creates an view based on the DbCreateViewEncoding
*/
@POST
@Path("/createView/")
@Consumes(MediaType.APPLICATION_JSON)
public Response createView(final CreateViewEncoding encoding) throws DbException {
long queryId;
try {
queryId = server.createView(encoding.viewName, encoding.viewDefinition, encoding.workers);
} catch (Exception e) {
throw new DbException();
}
/* Build the response to return the queryId */
ResponseBuilder response = Response.ok();
return response.entity(queryId).build();
}

/**
* Creates an UDF based on DbCreateUDFEncoding
*/
@POST
@Path("/createUDF/")
@Consumes(MediaType.APPLICATION_JSON)
public Response createUDF(final CreateUDFEncoding encoding) throws DbException {
long queryId;
try {
queryId = server.createUDF(encoding.udfName, encoding.udfDefinition, encoding.workers);
} catch (Exception e) {
throw new DbException();
}
/* Build the response to return the queryId */
ResponseBuilder response = Response.ok();
return response.entity(queryId).build();
}

/**
* @param dataset the dataset to be ingested.
* @return the created dataset resource.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
*/
package edu.washington.escience.myria.api.encoding;

import java.util.List;

import edu.washington.escience.myria.RelationKey;
import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.accessmethod.AccessMethod.IndexRef;

/**
*
*/
public class CreateIndexEncoding extends MyriaApiEncoding {
@Required
public RelationKey relationKey;
@Required
public Schema schema;
@Required
public List<IndexRef> indexes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
*
*/
package edu.washington.escience.myria.api.encoding;

import java.util.Set;

/**
*
*/
public class CreateUDFEncoding extends MyriaApiEncoding {
@Required
public String udfName;
@Required
public String udfDefinition;
@Required
public Set<Integer> workers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
*
*/
package edu.washington.escience.myria.api.encoding;

import java.util.Set;

/**
*
*/
public class CreateViewEncoding extends MyriaApiEncoding {
public String viewName;
public String viewDefinition;
public Set<Integer> workers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import edu.washington.escience.myria.api.MyriaApiException;
import edu.washington.escience.myria.api.encoding.QueryConstruct.ConstructArgs;
import edu.washington.escience.myria.operator.Operator;
import edu.washington.escience.myria.operator.SampledDbInsertTemp;

/**
* A JSON-able wrapper for the expected wire message for an operator. To add a new operator, two things need to be done.
Expand All @@ -32,6 +31,9 @@
@Type(name = "Consumer", value = ConsumerEncoding.class), @Type(name = "Counter", value = CounterEncoding.class),
@Type(name = "DbInsert", value = DbInsertEncoding.class),
@Type(name = "DbQueryScan", value = QueryScanEncoding.class),
@Type(name = "DbCreateIndex", value = CreateIndexEncoding.class),
@Type(name = "DbCreateView", value = CreateViewEncoding.class),
@Type(name = "DbCreateUDF", value = CreateUDFEncoding.class),
@Type(name = "Difference", value = DifferenceEncoding.class),
@Type(name = "DupElim", value = DupElimEncoding.class), @Type(name = "Empty", value = EmptyRelationEncoding.class),
@Type(name = "EOSController", value = EOSControllerEncoding.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,16 @@ private void addRelationMetadata(@Nonnull final SQLiteConnection sqliteConnectio
/* Second, populate the Schema table. */
statement =
sqliteConnection
.prepare("INSERT INTO relation_schema(user_name,program_name,relation_name,col_index,col_name,col_type) "
+ "VALUES (?,?,?,?,?,?);");
.prepare("INSERT INTO relation_schema(user_name,program_name,relation_name,col_index,col_name,col_type,is_indexed) "
+ "VALUES (?,?,?,?,?,?,?);");
statement.bind(1, relation.getUserName());
statement.bind(2, relation.getProgramName());
statement.bind(3, relation.getRelationName());
for (int i = 0; i < schema.numColumns(); ++i) {
statement.bind(4, i);
statement.bind(5, schema.getColumnName(i));
statement.bind(6, schema.getColumnType(i).toString());
statement.bind(7, 0);
statement.step();
statement.reset(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
*
*/
public class DbExecute extends RootOperator {
public class DbCreateUDF extends RootOperator {
/** Required for Java serialization. */
private static final long serialVersionUID = 1L;

Expand All @@ -23,17 +23,17 @@ public class DbExecute extends RootOperator {
/** The information for the database connection. */
private ConnectionInfo connectionInfo;

private final String sqlString;
private final String udfDefinition;

/**
* @param child the source of tuples to be inserted.
* @param relationKey the key of the table the tuples should be inserted into.
* @param connectionInfo the parameters of the database connection.
*/
public DbExecute(final Operator child, final String sqlString, final ConnectionInfo connectionInfo) {
public DbCreateUDF(final Operator child, final String sqlString, final ConnectionInfo connectionInfo) {
super(child);
this.connectionInfo = connectionInfo;
this.sqlString = sqlString;
udfDefinition = sqlString;
}

@Override
Expand All @@ -46,7 +46,7 @@ protected void init(final ImmutableMap<String, Object> execEnvVars) throws DbExc
accessMethod = AccessMethod.of(connectionInfo.getDbms(), connectionInfo, false);

/* Drop the table */
accessMethod.executeSQLCommand(sqlString);
accessMethod.executeSQLCommand(udfDefinition);
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/edu/washington/escience/myria/parallel/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
import edu.washington.escience.myria.operator.Apply;
import edu.washington.escience.myria.operator.DataOutput;
import edu.washington.escience.myria.operator.DbCreateIndex;
import edu.washington.escience.myria.operator.DbCreateUDF;
import edu.washington.escience.myria.operator.DbCreateView;
import edu.washington.escience.myria.operator.DbDelete;
import edu.washington.escience.myria.operator.DbExecute;
import edu.washington.escience.myria.operator.DbInsert;
import edu.washington.escience.myria.operator.DbQueryScan;
import edu.washington.escience.myria.operator.DuplicateTBGenerator;
Expand Down Expand Up @@ -1144,8 +1144,8 @@ public long createView(final String viewName, final String viewDefinition, final
/**
* Create a udf and register it in the catalog
*/
public long createUDFs(final String udfName, final String udfCommand, final Set<Integer> workers) throws DbException,
InterruptedException {
public long createUDF(final String udfName, final String udfDefinition, final Set<Integer> workers)
throws DbException, InterruptedException {
long queryID;
Set<Integer> actualWorkers = workers;
if (workers == null) {
Expand All @@ -1156,8 +1156,8 @@ public long createUDFs(final String udfName, final String udfCommand, final Set<
try {
Map<Integer, SubQueryPlan> workerPlans = new HashMap<>();
for (Integer workerId : actualWorkers) {
workerPlans.put(workerId, new SubQueryPlan(new DbExecute(EmptyRelation.of(Schema.EMPTY_SCHEMA), udfCommand,
null)));
workerPlans.put(workerId, new SubQueryPlan(new DbCreateUDF(EmptyRelation.of(Schema.EMPTY_SCHEMA),
udfDefinition, null)));
}
ListenableFuture<Query> qf =
queryManager.submitQuery("create UDF", "create UDF", "create UDF", new SubQueryPlan(new SinkRoot(
Expand All @@ -1173,7 +1173,7 @@ public long createUDFs(final String udfName, final String udfCommand, final Set<

/* Register the UDF to the catalog */
try {
catalog.registerUDFs(udfName, udfCommand);
catalog.registerUDFs(udfName, udfDefinition);
} catch (CatalogException e) {
throw new DbException(e);
}
Expand Down

0 comments on commit 8de5eb8

Please sign in to comment.