Skip to content

Commit

Permalink
Support for adding empty datasets (closes #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
okennedy committed Jan 29, 2020
1 parent aaa220b commit 57acad4
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
40 changes: 40 additions & 0 deletions resources/packages/common/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,46 @@
}
]
},
{
"format": [
{
"lspace": true,
"rspace": true,
"type": "const",
"value": "CREATE"
},
{
"lspace": true,
"rspace": true,
"type": "const",
"value": "EMPTY"
},
{
"lspace": true,
"rspace": true,
"type": "const",
"value": "DATASET"
},
{
"lspace": true,
"rspace": true,
"type": "var",
"value": "name"
}
],
"id": "empty",
"name": "Empty Dataset",
"parameter": [
{
"datatype": "string",
"hidden": false,
"id": "name",
"index": 0,
"name": "Dataset Name",
"required": true
}
]
},
{
"format": [
{
Expand Down
1 change: 1 addition & 0 deletions vizier/engine/packages/vizual/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
VIZUAL_INS_COL = 'insertColumn'
VIZUAL_INS_ROW = 'insertRow'
VIZUAL_LOAD = 'load'
VIZUAL_EMPTY_DS = 'empty'
VIZUAL_UNLOAD = 'unload'
VIZUAL_MOV_COL = 'moveColumn'
VIZUAL_MOV_ROW = 'moveRow'
Expand Down
72 changes: 72 additions & 0 deletions vizier/engine/packages/vizual/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import vizier.engine.packages.vizual.api.base as apibase
from vizier.api.webservice import server
from vizier.config.app import AppConfig
import vizier.mimir as mimir
from vizier.datastore.mimir.dataset import MimirDatasetColumn

"""Property defining the API class if instantiated from dictionary."""
PROPERTY_API = 'api'
Expand Down Expand Up @@ -105,6 +107,11 @@ def compute(self, command_id, arguments, context):
args=arguments,
context=context
)
elif command_id == cmd.VIZUAL_EMPTY_DS:
return self.compute_empty_dataset(
args=arguments,
context=context
)
elif command_id == cmd.VIZUAL_UNLOAD:
return self.compute_unload_dataset(
args=arguments,
Expand Down Expand Up @@ -465,6 +472,71 @@ def compute_load_dataset(self, args, context):
resources=result.resources
)
)

def compute_empty_dataset(self, args, context):
"""Execute empty dataset command.
Parameters
----------
args: vizier.viztrail.command.ModuleArguments
User-provided command arguments
context: vizier.engine.task.base.TaskContext
Context in which a task is being executed
Returns
-------
vizier.engine.task.processor.ExecResult
"""
outputs = ModuleOutputs()
default_columns = [ ("''", "unnamed_column") ]
ds_name = args.get_value(pckg.PARA_NAME).lower()
if ds_name in context.datasets:
raise ValueError('dataset \'' + ds_name + '\' exists')
if not is_valid_name(ds_name):
raise ValueError('invalid dataset name \'' + ds_name + '\'')
try:
source = "SELECT {};".format(", ".join(
default_val + " AS " + col_name
for default_val, col_name in default_columns
))
view_name = mimir.createView(
dict(),
source
)

columns = [
MimirDatasetColumn(
identifier=col_id,
name_in_dataset=col_defn[1]
)
for col_defn, col_id in zip(default_columns, range(len(default_columns)))
]

ds = context.datastore.register_dataset(
table_name=view_name,
columns=columns,
row_counter=1
)
provenance = ModuleProvenance(
write={
ds_name: DatasetDescriptor(
identifier=ds.identifier,
columns=ds.columns,
row_count=ds.row_count
)
}
)
outputs.stdout.append(TextOutput("Empty dataset '{}' created".format(ds_name)))
except Exception as ex:
provenance = ModuleProvenance()
outputs.error(ex)
return ExecResult(
is_success=(len(outputs.stderr) == 0),
outputs=outputs,
provenance=provenance
)



def compute_unload_dataset(self, args, context):
"""Execute unload dataset command.
Expand Down
14 changes: 10 additions & 4 deletions vizier/viztrail/module/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ def format_stack_trace(ex):
)
for element in trace
])
trace = (
[" ... caused by "+trace[0]]+
[" ... called by "+line for line in trace[1:]]
)
if len(trace) > 0:
trace = (
[" ... caused by "+trace[0]]+
[" ... called by "+line for line in trace[1:]]
)
else:
return "INTERNAL ERROR\n{}".format(ex)
return "{}".format("\n".join(trace))


Expand Down Expand Up @@ -137,6 +140,9 @@ def error(self, ex):
message = message + ":\n " + str(traceback.format_exc())
except Exception as e:
message = template.format(type(e).__name__, e.args)
if debug_is_on():
message += "\n"+format_stack_trace(e)

self.stderr.append(TextOutput(message))
return self

Expand Down

0 comments on commit 57acad4

Please sign in to comment.