Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't exec impala function at INSERT Statement #27

Open
zbyjm6969 opened this issue Nov 3, 2020 · 2 comments
Open

Couldn't exec impala function at INSERT Statement #27

zbyjm6969 opened this issue Nov 3, 2020 · 2 comments

Comments

@zbyjm6969
Copy link

Just like title, When I exec insert statement like
insert into table TABLE_A (id,user_name) select id,user_name from TABLE_B

It good to work, But if I give a function like
insert into table TABLE_A (id,user_name,age) select id,user_name,cast(age as string) from TABLE_B
No fail message and no data insert

@shaloi
Copy link
Collaborator

shaloi commented Nov 6, 2020

Hi,

I tried to reproduce your issue as follows:

TABLE A:
+-----------------------+----------+---------+
| name                  | type     | comment |
+-----------------------+----------+---------+
| id             | int      |         |
| name           | string   |         |
| age            | smallint |         |
| sex            | string   |         |
+-----------------------+----------+---------+

TABLE B:
+-----------------------+----------+---------+
| name                  | type     | comment |
+-----------------------+----------+---------+
| id             | int      |         |
| name           | string   |         |
| age            | string |         |
| sex            | string   |         |
+-----------------------+----------+---------+

I tried to insert data from table_a to table_b using the following code:

package main

import (
    "context"
    "database/sql"
    "log"

    impala "github.com/bippio/go-impala"
)

func main() {

    opts := impala.DefaultOptions

    opts.Host = "Impala Host"
    opts.Port = "21050"

    // enable LDAP authentication:
    opts.UseLDAP = true
    opts.Username = "user"
    opts.Password = "pass"

    // enable TLS
    opts.UseTLS = true
    opts.CACertPath = "/path/to.cert.pem"

    connector := impala.NewConnector(&opts)
    db := sql.OpenDB(connector)
    defer db.Close()

    ctx := context.Background()

    _, err := db.QueryContext(ctx, "insert into default.table_b(id, name, age, sex) select id, name, cast(age as string), sex from default.table_a")
    if err != nil {
        log.Fatal(err)
    }
}

and it worked as expected. The data were inserted to table_b from table_a.

If I try use an incompatible column with cast, the program throws error like below:

2020/11/06 19:15:29 AnalysisException: Target table 'default.table_b' is incompatible with source expressions.
Expression 'CAST(id AS STRING)' (type: STRING) is not compatible with column 'id' (type: INT)
exit status 1

Have you tried running your query through Hue or Impala Shell? What error does that throw?

@zbyjm6969
Copy link
Author

Hi,

I tried to reproduce your issue as follows:

TABLE A:
+-----------------------+----------+---------+
| name                  | type     | comment |
+-----------------------+----------+---------+
| id             | int      |         |
| name           | string   |         |
| age            | smallint |         |
| sex            | string   |         |
+-----------------------+----------+---------+

TABLE B:
+-----------------------+----------+---------+
| name                  | type     | comment |
+-----------------------+----------+---------+
| id             | int      |         |
| name           | string   |         |
| age            | string |         |
| sex            | string   |         |
+-----------------------+----------+---------+

I tried to insert data from table_a to table_b using the following code:

package main

import (
    "context"
    "database/sql"
    "log"

    impala "github.com/bippio/go-impala"
)

func main() {

    opts := impala.DefaultOptions

    opts.Host = "Impala Host"
    opts.Port = "21050"

    // enable LDAP authentication:
    opts.UseLDAP = true
    opts.Username = "user"
    opts.Password = "pass"

    // enable TLS
    opts.UseTLS = true
    opts.CACertPath = "/path/to.cert.pem"

    connector := impala.NewConnector(&opts)
    db := sql.OpenDB(connector)
    defer db.Close()

    ctx := context.Background()

    _, err := db.QueryContext(ctx, "insert into default.table_b(id, name, age, sex) select id, name, cast(age as string), sex from default.table_a")
    if err != nil {
        log.Fatal(err)
    }
}

and it worked as expected. The data were inserted to table_b from table_a.

If I try use an incompatible column with cast, the program throws error like below:

2020/11/06 19:15:29 AnalysisException: Target table 'default.table_b' is incompatible with source expressions.
Expression 'CAST(id AS STRING)' (type: STRING) is not compatible with column 'id' (type: INT)
exit status 1

Have you tried running your query through Hue or Impala Shell? What error does that throw?

After my test, It not work again.
I running my query via impala-shell, And no error throw.

I use go mod in my project, Do you think that is problem?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants