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

Syntax Error on nested queries from google spreadsheet with blank column names #2620

Closed
metheos opened this issue Jun 22, 2018 · 5 comments
Closed
Labels

Comments

@metheos
Copy link

metheos commented Jun 22, 2018

Redash 4.0.1+b4038
Pulling data from google spreadsheet
the spreadsheet has some columns with blank headers
If I run a query against the query results from pulling in the spreadsheet (e.g. query_45) I get an error

File "/opt/redash/redash.4.0.1.b4038/redash/query_runner/query_results.py", line 92, in create_table
    connection.execute(create_table)
OperationalError: near ")": syntax error

This is caused by create_table with a create table string that contains a blank column header at the end.
e.g.

CREATE TABLE table_46 (Name, Phone, )

I hacked a fix into my query_results.py to create named columns for blank columns.

------------------query_results.py:79--------------------

def fix_column_name(name,columncounter):
    if name.strip() == '':
        name = u"BLANK{colno}".format(colno=columncounter)

    return name.replace(':', '_').replace('.', '_').replace(' ', '_')


def create_table(connection, table_name, query_results):
    columns = [column['name']
               for column in query_results['columns']]
    safe_columns = []
    colno = 0
    for column in columns:
        safe_columns.append(fix_column_name(column,colno))
        colno = colno + 1 
@ariarijp
Copy link
Member

ariarijp commented Jul 2, 2018

@arikfr I have two solutions for it in Spreadsheet Query Runner.

  1. Raise an exception when blank column name found
  2. Rename blank column names implicitly (example: BLANK_1, BLANK_2...)

Do you have another solutions?

@arikfr
Copy link
Member

arikfr commented Jul 2, 2018

Let's go with option #2 - rename the columns. But instead of blank_, maybe column_ + column number?

@arikfr arikfr added the Backend label Jul 2, 2018
@ariarijp
Copy link
Member

ariarijp commented Jul 2, 2018

Good, column_{col_num} looks more better and user friendly.

However, I would like to clarify your idea.

Does column number means A (Excel style) or 1 (Numeric style) ?

@metheos
Copy link
Author

metheos commented Jul 2, 2018

I would suggest Excel style with letters since that's what excel and google docs both use for the column id. It would make it easier for someone to refer back to their spreadsheet if it's a complex one.

@arikfr
Copy link
Member

arikfr commented Jul 29, 2018

Closed in #2663.

@arikfr arikfr closed this as completed Jul 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants