databricks / databricks-sql-go

Golang database/sql driver for Databricks SQL.
Apache License 2.0
34 stars 38 forks source link

Unable to connect to host #144

Open ezbercihk opened 11 months ago

ezbercihk commented 11 months ago

With 1.3.1 upgrade, we start to get this error when we try to run SELECT queries and when downgraded to 1.3.0, this issue is no longer there. Below is the error we get back:

"error":"databricks: driver error: error initializing thrift client: databricks: missing Hostname"

rcypher-databricks commented 11 months ago

I'm sorry you've encountered this issue. Could I get some more information about how you are connecting and running the query?

rcypher-databricks commented 11 months ago

Looking at 1.3.1 the only thing that release added is a bug fix when handling query results. I'm not sure how it would affect creating a connection.

ezbercihk commented 11 months ago

@rcypher-databricks apologies for the silence.. I will get you the details on how we connect shortly.. we also didn't change anything on our side but just upgraded to the new version, and it stopped working with this error. I will get back to you with more details.

ezbercihk commented 11 months ago

@rcypher-databricks here's what our code that makes the connection looks like:

func initializeConnection(cfg *config.Config) (*sql.DB, error) {

    var endpointPath string
    if strings.Contains(cfg.Databricks.SQLEndpointId, "/") {
        endpointPath = fmt.Sprintf("/sql/protocolv1/o/%s", cfg.Databricks.SQLEndpointId)
    } else {
        endpointPath = fmt.Sprintf("/sql/1.0/endpoints/%s", cfg.Databricks.SQLEndpointId)
    }

    connector, err := dbsql.NewConnector(
        dbsql.WithServerHostname(cfg.Databricks.URL),
        dbsql.WithPort(443),
        dbsql.WithHTTPPath(endpointPath),
        dbsql.WithAccessToken(cfg.Databricks.PAT),
        dbsql.WithUserAgentEntry("Kobai Saturn"),
        dbsql.WithInitialNamespace(cfg.Databricks.CatalogName, cfg.Top.SchemaPrefix),
    )
    if err != nil {
        return nil, err
    }
    return sql.OpenDB(connector), nil
}

It think it is pretty standard, and like I said, nothing changed in our code. The only change was upgrading the package and we started getting that error.

yunbodeng-db commented 11 months ago

@rcypher-databricks here's what our code that makes the connection looks like:

func initializeConnection(cfg *config.Config) (*sql.DB, error) {

  var endpointPath string
  if strings.Contains(cfg.Databricks.SQLEndpointId, "/") {
      endpointPath = fmt.Sprintf("/sql/protocolv1/o/%s", cfg.Databricks.SQLEndpointId)
  } else {
      endpointPath = fmt.Sprintf("/sql/1.0/endpoints/%s", cfg.Databricks.SQLEndpointId)
  }

  connector, err := dbsql.NewConnector(
      dbsql.WithServerHostname(cfg.Databricks.URL),
      dbsql.WithPort(443),
      dbsql.WithHTTPPath(endpointPath),
      dbsql.WithAccessToken(cfg.Databricks.PAT),
      dbsql.WithUserAgentEntry("Kobai Saturn"),
      dbsql.WithInitialNamespace(cfg.Databricks.CatalogName, cfg.Top.SchemaPrefix),
  )
  if err != nil {
      return nil, err
  }
  return sql.OpenDB(connector), nil
}

It think it is pretty standard, and like I said, nothing changed in our code. The only change was upgrading the package and we started getting that error.

What was your cfg looking like? The error message is pretty clear so we should check the input to the driver. Can you turn on the logging and check the logs?