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

Failed to fetch semantic model #89

Open
antfido opened this issue Sep 9, 2024 · 11 comments
Open

Failed to fetch semantic model #89

antfido opened this issue Sep 9, 2024 · 11 comments

Comments

@antfido
Copy link

antfido commented Sep 9, 2024

Hey,

I redeployed the extension (I couldn't find a bug in my former deploy), and now I'm getting an error as on the screen below:

Screenshot 2024-09-09 at 15 49 20

Did anyone experience a similar error ? How did you handle it ?

I ran out what to change, my .env file looks good. Maybe I wrongly define example_id in examples ? I defines it as
<my_Looker_model_name>:<my_Looker_explore_name> . I don't add .model and .explore .

Thanks !

@antfido
Copy link
Author

antfido commented Sep 10, 2024

hey @LukaFontanilla - do you know what can be a reason for that ? thnx!

@antfido antfido closed this as completed Sep 10, 2024
@antfido antfido reopened this Sep 10, 2024
@vijayram0690
Copy link

@antfido was this issue fixed, i am also running into similar issue.

@LukaFontanilla how can we fix the above issue.

@antfido antfido closed this as completed Sep 25, 2024
@antfido antfido reopened this Sep 25, 2024
@antfido
Copy link
Author

antfido commented Sep 25, 2024

Nope, still stucked here @vijayram0690

@antfido
Copy link
Author

antfido commented Sep 26, 2024

@vijayram0690 did you solve it ?

@antfido antfido closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
@antfido antfido reopened this Sep 26, 2024
@LukaFontanilla
Copy link
Collaborator

I assume this error is returned when the extension first starts up and not after a NL request is submitted? It would be helpful to understand what requests are failing. Can you please check the browser dev tools and both the "Console" and "Network" tabs and share any Looker specific errors you find there? Given the error message I would assume there is a failing Looker API call. It would be helpful to see what that is.

As for the newer Explore Assistant deployment, there are 3 BigQuery tables that are provisioned -> explore_assistant_examples, explore_assistant_refinement_examples, & explore_assistant_samples. Each of these tables should have a row for the given model and explore you want to use with the Explore Assistant (we are no longer reliant on a single set of environment variables for this). Additionally each explore_id value should be in the format you listed, where the model name and explore name are separated by a single ":".

@antfido
Copy link
Author

antfido commented Oct 28, 2024

Hey,

so here are the screenshots from console:
Screenshot 2024-10-28 at 12 39 05

Screenshot 2024-10-28 at 12 38 34 Screenshot 2024-10-28 at 12 38 21 For the second part - in BQ and in the config files it's defined with one semicolon, I don't know why error adds one more...

Thanks a lot for your help @LukaFontanilla .

@antfido
Copy link
Author

antfido commented Nov 15, 2024

hey @LukaFontanilla - would you be able to look into that one ? Thnx a lot ! :)

@antfido antfido closed this as completed Nov 15, 2024
@antfido antfido reopened this Nov 15, 2024
@dassowmd
Copy link

I'm having a similar issue. I think its related to my exploreKey having '::' in it instead of the expected ':' the code is looking for.

@antfido
Copy link
Author

antfido commented Dec 16, 2024

@dassowmd it's just generic output of the error (defined wrongly) so I wouldnt bother about it. is it working for you know ?

@antfido antfido closed this as completed Dec 16, 2024
@antfido antfido reopened this Dec 16, 2024
@dassowmd
Copy link

dassowmd commented Dec 16, 2024

@antfido I think the issue is that the EXPLORE_ID in the .env file has a single colon, but Looker delimits with a double colon. I didn't catch it, which sent me down a rabbit hole. Once I figured that out it seems to be working fine.

Would it be possible to validate that the EXPLORE_ID set in that file is properly formatted to only have a single colon?

@dassowmd
Copy link

dassowmd commented Dec 17, 2024

@antfido I tried pushing the feature, but can't on this repo.

But I was thinking something like this in explore-assistant-examples/load_examples.py

def validate(args):
    """Validate the given explore_id."""
    if '::' in args.explore_id:
        raise argparse.ArgumentTypeError(f"Invalid explore_id: {args.explore_id}. '::' not allowed")

def main():
    args = parse_arguments()

    # validate before making changes
    validate(args)

    # delete existing rows
    client = get_bigquery_client(args.project_id)
    delete_existing_rows(client, args.project_id, args.dataset_id, args.table_id, args.explore_id)

    # load data from file and insert into BigQuery
    data = load_data_from_file(args.json_file)
    insert_data_into_bigquery(client, args.dataset_id, args.table_id, args.column_name, args.explore_id, data)

Full file:

import argparse
from google.cloud import bigquery
import json

def parse_arguments():
    """Parse command line arguments."""
    parser = argparse.ArgumentParser(description='Load JSON data into BigQuery')
    parser.add_argument('--project_id', type=str, required=True, help='Google Cloud project ID')
    parser.add_argument('--dataset_id', type=str, help='BigQuery dataset ID', default='explore_assistant')
    parser.add_argument('--table_id', type=str, help='BigQuery table ID', default='explore_assistant_examples')
    parser.add_argument('--column_name', type=str, help='Column name, if different than "examples"', default='examples')
    parser.add_argument('--explore_id', type=str, required=True, help='The name of the explore in the model:explore_name format')
    parser.add_argument('--json_file', type=str, help='Path to the JSON file containing the data', default='examples.json')
    return parser.parse_args()

def get_bigquery_client(project_id):
    """Initialize and return a BigQuery client."""
    return bigquery.Client(project=project_id)

def delete_existing_rows(client, project_id, dataset_id, table_id, explore_id):
    """Delete existing rows with the given explore_id."""
    full_table_id = f"{project_id}.{dataset_id}.{table_id}"
    delete_query = f"DELETE FROM `{full_table_id}` WHERE explore_id = @explore_id"
    job_config = bigquery.QueryJobConfig(
        query_parameters=[bigquery.ScalarQueryParameter("explore_id", "STRING", explore_id)]
    )
    delete_job = client.query(delete_query, job_config=job_config)
    delete_job.result()  # Wait for the job to complete
    if delete_job.errors:
        print(f"Failed to delete existing rows for explore_id {explore_id}: {delete_job.errors}")
    else:
        print(f"Successfully deleted rows for explore_id {explore_id}")

def load_data_from_file(json_file_path):
    """Load data from a JSON file."""
    with open(json_file_path, 'r') as file:
        return json.load(file)

def insert_data_into_bigquery(client, dataset_id, table_id, column_name, explore_id, data):
    """Insert data into BigQuery using a SQL INSERT statement."""
    # Convert the data to a JSON string
    data_json = json.dumps(data)

    # Create a BigQuery SQL INSERT statement
    insert_query = f"""
    INSERT INTO `{dataset_id}.{table_id}` (explore_id, `{column_name}`)
    VALUES (@explore_id, @examples)
    """

    # Set up query parameters to prevent SQL injection
    job_config = bigquery.QueryJobConfig(
        query_parameters=[
            bigquery.ScalarQueryParameter("explore_id", "STRING", explore_id),
            bigquery.ScalarQueryParameter("examples", "STRING", data_json)
        ]
    )

    # Execute the query
    query_job = client.query(insert_query, job_config=job_config)
    query_job.result()  # Wait for the query to complete

    # Check if the query resulted in any errors
    if query_job.errors is None:
        print("Data has been successfully inserted.")
    else:
        print(f"Encountered errors while inserting data: {query_job.errors}")

def validate(args):
    """Validate the given explore_id."""
    if '::' in args.explore_id:
        raise argparse.ArgumentTypeError(f"Invalid explore_id: {args.explore_id}. '::' not allowed")

def main():
    args = parse_arguments()

    # validate before making changes
    validate(args)

    # delete existing rows
    client = get_bigquery_client(args.project_id)
    delete_existing_rows(client, args.project_id, args.dataset_id, args.table_id, args.explore_id)

    # load data from file and insert into BigQuery
    data = load_data_from_file(args.json_file)
    insert_data_into_bigquery(client, args.dataset_id, args.table_id, args.column_name, args.explore_id, data)

if __name__ == '__main__':
    main()

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

No branches or pull requests

4 participants