[
https://issues.apache.org/jira/browse/CALCITE-4956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17463653#comment-17463653
]
Francis Chuang edited comment on CALCITE-4956 at 12/22/21, 8:55 AM:
--------------------------------------------------------------------
The reason we don't want to set the info key-value map in the DSN is because
it's quite possible that a key value you want to use will collide with the keys
in the dsn:
https://calcite.apache.org/avatica/docs/go_client_reference.html#dsn-data-source-name
That's why we implement the connector interface:
https://pkg.go.dev/database/sql/driver#Connector
This allows you to set your info key-value map or custom HTTP client and use
OpenDB: https://pkg.go.dev/database/sql#OpenDB
Which is what I am doing in my example:
{code:go}
c := avatica.NewConnector(dsn)
// Adding custom info
c.Info = map[string]string{
"x": "y",
}
// Connect
db := sql.OpenDB(c)
// Use db here like any standard sql.DB
{code}
Also, `NewConnector` should only accept a dsn as setting the info key-value map
is optional. This is intentionally by design.
was (Author: francischuang):
The reason we don't want to set the info key-value map in the DSN is because
it's quite possible that a key value you want to use will collide with the keys
in the dsn:
https://calcite.apache.org/avatica/docs/go_client_reference.html#dsn-data-source-name
That's why we implement the connector interface:
https://pkg.go.dev/database/sql/driver#Connector
This allows you to set your info key-value map or custom HTTP client and use
OpenDB: https://pkg.go.dev/database/sql#OpenDB
Which is what I am doing in my example:
{code:go}
c := avatica.NewConnector(dsn)
// Adding custom info
c.Info = map[string]string{
"x": "y",
}
// Connect
db := sql.OpenDB(c)
// Use db here like any standard sql.DB
{code}
> calcite-avatica-go should post info when open connection
> --------------------------------------------------------
>
> Key: CALCITE-4956
> URL: https://issues.apache.org/jira/browse/CALCITE-4956
> Project: Calcite
> Issue Type: Bug
> Components: avatica-go
> Affects Versions: avatica-go-5.0.0
> Reporter: maxwellguo
> Assignee: Francis Chuang
> Priority: Major
>
> see
> https://calcite.apache.org/avatica/docs/json_reference.html#openconnectionrequest
>
> for openconnection request we can set info that is some key-value pairs .but
> for avatica-go we do not get the chance to post the info, though
> https://github.com/apache/calcite-avatica-go/blob/master/driver.go#L88 the
> code do set some info but after seeing the code
> https://github.com/apache/calcite-avatica-go/blob/master/driver.go#L61 we
> will know the info is nil, so the info will never be posted.
> after reviewing the database/sql of go's source code, I found that the
> https://github.com/apache/calcite-avatica-go/blob/master/driver.go#L60
> NewConnector will only go one input paramters that is dsn ,so if we want to
> post some info ,it is useless.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)