Skip to content

Commit

Permalink
Fix desktop asar launcher, add shorthand for dumping json to dsq (#133)
Browse files Browse the repository at this point in the history
* Fix for interval grouping

* Fix for windows

* Shorthand for dsq

* Fix for tsc

* Fix for tsc
  • Loading branch information
eatonphil authored Dec 22, 2021
1 parent 9c3adc2 commit e4344c3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
11 changes: 10 additions & 1 deletion desktop/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { registerRPCHandlers } from './rpc';
import { initialize } from './runner';
import { flushUnwritten, storeHandlers } from './store';

const binaryExtension: Record<string, string> = {
darwin: '',
linux: '',
win32: '.exe',
};

function main() {
configureLogger();
log.info(APP_NAME, VERSION, DEBUG ? 'DEBUG' : '');
Expand All @@ -28,7 +34,10 @@ function main() {
const { handlers, project } = initialize({
subprocess: {
node: path.join(__dirname, 'desktop_runner.js'),
go: path.join(__dirname, 'go_desktop_runner'),
go: path.join(
__dirname,
'go_desktop_runner' + binaryExtension[process.platform]
),
},
additionalHandlers: storeHandlers,
});
Expand Down
2 changes: 1 addition & 1 deletion desktop/scripts/release.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cp icon.png build/icon.png
cp icon.ico build/icon.ico
cp icon.icns build/icon.icns
yarn electron-packager --asar --overwrite --icon=build/icon.png --out=releases --build-version={arg0} --app-version={arg0} . "DataStation Community Edition"
zip -9 -r releases/datastation-{os}-{arch}-{arg0}.zip "releases/DataStation Community Edition-{os}-{arch}"
#zip -9 -r releases/datastation-{os}-{arch}-{arg0}.zip "releases/DataStation Community Edition-{os}-{arch}"
13 changes: 13 additions & 0 deletions runner/cmd/dsq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ Or:
$ dsq testdata.ndjson "SELECT name, AVG(time) FROM {} GROUP BY name ORDER BY AVG(time) DESC"
```

## Transforming data to JSON without querying

As a shorthand for `dsq testdata.csv "SELECT * FROM {}"` to convert
supported file types to JSON you can skip the query and the converted
JSON will be dumped to stdout.

For example:

```bash
$ dsq testdata.csv
[{...some csv data...},{...some csv data...},...]
```

## Supported Data Types

| Name | File Extension(s) | Notes |
Expand Down
44 changes: 33 additions & 11 deletions runner/cmd/dsq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func getResult(res interface{}) error {
arg := firstNonFlagArg

mimetype := resolveContentType(arg)
if mimetype == "" {
return fmt.Errorf(`First argument when used in a pipe should be file extension or content type. e.g. 'cat test.csv | dsq csv "SELECT * FROM {}"'`)
}

cti := runner.ContentTypeInfo{Type: mimetype}

Expand All @@ -57,11 +54,19 @@ func getResult(res interface{}) error {
}

if !runAsFile {
if mimetype == "" {
return fmt.Errorf(`First argument when used in a pipe should be file extension or content type. e.g. 'cat test.csv | dsq csv "SELECT * FROM {}"'`)
}

err := runner.TransformReader(os.Stdin, "", cti, out)
if err != nil {
return err
}
} else {
if arg == "" {
return fmt.Errorf(`First argument when not used in a pipe should be a file. e.g. 'dsq test.csv "SELECT COUNT(1) FROM {}"'`)
}

err := runner.TransformFile(arg, runner.ContentTypeInfo{}, out)
if err != nil {
return err
Expand All @@ -73,13 +78,10 @@ func getResult(res interface{}) error {
}

func main() {
if len(os.Args) < 3 {
log.Fatal(`Expected data source and query. e.g. 'dsq names.csv "SELECT name FROM {}"'`)
}

log.SetFlags(0)
runner.Verbose = false
inputTable := "{}"
lastNonFlagArg := ""
var nonFlagArgs []string
for i, arg := range os.Args[1:] {
if arg == "-i" || arg == "--input-table-alias" {
if i > len(os.Args)-2 {
Expand All @@ -95,11 +97,21 @@ func main() {
continue
}

if firstNonFlagArg == "" {
firstNonFlagArg = arg
if arg == "-h" || arg == "--help" {
log.Println("See the README on Github for details.\n\nhttps://github.com/multiprocessio/datastation/blob/main/runner/cmd/dsq/README.md")
return
}

lastNonFlagArg = arg
nonFlagArgs = append(nonFlagArgs, arg)
}

if len(nonFlagArgs) > 0 {
firstNonFlagArg = nonFlagArgs[0]
}

lastNonFlagArg := ""
if len(nonFlagArgs) > 1 {
lastNonFlagArg = nonFlagArgs[len(nonFlagArgs)-1]
}

var res []map[string]interface{}
Expand All @@ -108,6 +120,16 @@ func main() {
log.Fatal(err)
}

if lastNonFlagArg == "" {
encoder := json.NewEncoder(os.Stdout)
err := encoder.Encode(res)
if err != nil {
log.Fatal(err)
}

return
}

sampleSize := 50
shape, err := runner.GetArrayShape(firstNonFlagArg, res, sampleSize)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions runner/filagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func evalFilaggPanel(project *ProjectState, pageIndex int, panel *PanelInfo) err
qt := ansiSQLQuote
fg := panel.Filagg

_, panelIndex, err := getDependentPanel(project.Pages[pageIndex], fg.PanelSource)
_, panelIndex, err := getDependentPanel(project.Pages[pageIndex], fg.GetPanelSource())
if err != nil {
return err
}
Expand All @@ -153,7 +153,7 @@ func evalFilaggPanel(project *ProjectState, pageIndex int, panel *PanelInfo) err
groupColumn := quote(fg.GroupBy, qt.identifier)

groupExpression := quote(fg.GroupBy, qt.identifier)
if interval, err := strconv.Atoi(fg.WindowInterval); err == nil {
if interval, err := strconv.Atoi(fg.WindowInterval); err == nil && interval > 0 {
intervalSeconds := fmt.Sprintf("%d", interval*60)
groupExpression = `DATETIME(STRFTIME("%s", ` + fg.GroupBy + `) - STRFTIME("%s", ` + fg.GroupBy + `) % ` + intervalSeconds + `, "unixepoch")`
groupColumn = groupExpression + " " + fg.GroupBy
Expand Down Expand Up @@ -223,6 +223,8 @@ func evalFilaggPanel(project *ProjectState, pageIndex int, panel *PanelInfo) err
orderByClause,
fg.Limit)

Logln("filagg query: %s", query)

fakepanel := &PanelInfo{
Content: query,
Type: ProgramPanel,
Expand Down
16 changes: 14 additions & 2 deletions runner/state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package runner

import "time"
import (
"fmt"
"time"
)

type PanelResult struct {
Exception interface{} `json:"exception" db:"exception"`
Expand Down Expand Up @@ -174,6 +177,7 @@ const (
AbsoluteRange TimeSeriesRangeType = "absolute"
RelativeRange = "relative"
FixedRange = "fixed"
None = "none"
)

type TimeSeriesRange struct {
Expand All @@ -199,7 +203,7 @@ const (
)

type FilaggPanelInfoFilagg struct {
PanelSource string `json:"panelSource"`
PanelSource interface{} `json:"panelSource"`
Filter string `json:"filter"`
Range TimeSeriesRange `json:"range"`
AggregateType AggregateType `json:"aggregateType"`
Expand All @@ -211,6 +215,14 @@ type FilaggPanelInfoFilagg struct {
Limit int `json:"limit"`
}

func (fpif FilaggPanelInfoFilagg) GetPanelSource() string {
if s, ok := fpif.PanelSource.(string); ok {
return s
}

return fmt.Sprintf("%v", fpif.PanelSource)
}

type FilaggPanelInfo struct {
Filagg FilaggPanelInfoFilagg `json:"filagg"`
}
Expand Down

0 comments on commit e4344c3

Please sign in to comment.