databricks-sql-go icon indicating copy to clipboard operation
databricks-sql-go copied to clipboard

Unable to connect to host

Open ezbercihk opened this issue 2 years ago • 5 comments

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"

ezbercihk avatar Jul 19 '23 01:07 ezbercihk

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 avatar Jul 19 '23 14:07 rcypher-databricks

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.

rcypher-databricks avatar Jul 27 '23 20:07 rcypher-databricks

@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 avatar Jul 27 '23 20:07 ezbercihk

@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.

ezbercihk avatar Jul 28 '23 18:07 ezbercihk

@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?

yunbodeng-db avatar Jul 31 '23 16:07 yunbodeng-db