FeatureEngineeringClient and Databricks Connect

antonioferegrin
New Contributor
Hello everyone, I want to use Databricks Connect to connect externally to my clusters and run code, and while Databricks connect works without any issue, like this:

 

```
from databricks.sdk.core import Config

 

config = Config(cluster_id="XXXX")
spark = SparkSession.builder.sdkConfig(config).getOrCreate()

 

catalog = "my_test_catalog"
schema = "my_schema"
table = "my_table"

 

spark.sql(f"CREATE CATALOG IF NOT EXISTS {catalog}")
spark.sql(f"USE CATALOG {catalog}")
spark.sql(f"CREATE SCHEMA IF NOT EXISTS {schema}")
spark.sql(f"USE SCHEMA {schema}")
 
```
 
However, I try to use the `FeatureEngineeringClient` to create a table like this:
```
from databricks.feature_engineering import FeatureEngineeringClient
from pyspark.sql.types import StringType, StructField, StructType, TimestampType

 

log_message_schema = StructType(
[
StructField("message", StringType(), True),
StructField("application", StringType(), True),
StructField("request_id", StringType(), False),
StructField("timestamp", TimestampType(), False),
StructField("levelname", StringType(), True),
StructField("data", StringType(), True),
StructField("run_id", StringType(), True),
StructField("model_name", StringType(), True),
]
)

 

feature_engineering_client = FeatureEngineeringClient()

 

feature_engineering_client.create_table(
name=f"{catalog}.{schema}.{table}_offline",
primary_keys=["request_id", "timestamp"],
timestamp_keys=["timestamp"],
schema=log_message_schema,
)
```

 

I get an authentication error:

 

```
Exception: {'error_code': '401', 'message': 'Unauthorized'}
```

 

Do you know why this could be happening?