-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalisa_wrap_test.go
71 lines (62 loc) · 1.95 KB
/
alisa_wrap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2019 The SQLFlow Authors. All rights reserved.
// 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 goalisa
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestQueryAlisaTask(t *testing.T) {
a := assert.New(t)
ali := newAlisaFromEnv(t)
cmd := "select \"Alice\" as name, 23.8 as age, 56000 as salary;"
res, err := ali.query(cmd)
a.NoError(err)
// schema, header
a.Equal(len(res.columns), 3)
a.Equal(res.columns[0].name, "name")
a.Equal(res.columns[0].typ, "string")
a.Equal(res.columns[1].name, "age")
a.Equal(res.columns[1].typ, "double")
a.Equal(res.columns[2].name, "salary")
a.Equal(res.columns[2].typ, "bigint")
// body
a.Equal(len(res.body), 1)
a.Equal(len(res.body[0]), 3)
a.Equal(res.body[0][0], "Alice")
a.Equal(res.body[0][1], "23.8")
a.Equal(res.body[0][2], "56000")
}
func TestExecAlisaTask(t *testing.T) {
a := assert.New(t)
ali := newAlisaFromEnv(t)
cmd := "CREATE TABLE IF NOT EXISTS sqlflow_alisa_test_table(c1 STRING);"
err := ali.exec(cmd)
a.NoError(err)
// then describe table
cmd = "DESCRIBE sqlflow_alisa_test_table;"
res, err := ali.query(cmd)
a.NoError(err)
a.True(len(res.body) > 0)
}
func TestExecAlisaTaskHints(t *testing.T) {
a := assert.New(t)
ali := newAlisaFromEnv(t)
hint := `set odps.sql.select.output.format="HumanReadable";`
qry := `SELECT 1;`
goodCmd := hint + "\n" + qry
_, err := ali.query(goodCmd)
a.NoError(err)
badCmd := hint + qry
_, err = ali.query(badCmd)
a.Error(err)
}