superset icon indicating copy to clipboard operation
superset copied to clipboard

sql error

Open sheweichun opened this issue 10 years ago • 9 comments

I use caravel for apache kylin,I got some errors beblow:

pykylin.errors.Error) Error when requesting: "query", exception: "Encountered "AS count" at line 1, column 17. Was expecting one of: "FROM" ... "," ... "AS" ... "AS" ... "AS" ... "AS" ... "AS" ... "NOT" ... "IN" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "=" ... ">" ... "<" ... "<=" ... ">=" ... "<>" ... "+" ... "-" ... "" ... "/" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "MULTISET" ... "[" ... "FILTER" ... "OVER" ... " [SQL: u"SELECT COUNT() AS count \nFROM parquet_test \nWHERE datetime >= '2016-06-16 19:26:58.000000' AND datetime <= '2016-06-23 19:26:58.000000'\n LIMIT 50000"]

(pykylin.errors.Error) Error when requesting: "query", exception: "Encountered "AS timestamp" at line 1, column 17. Was expecting one of: "FROM" ... "," ... "AS" ... "AS" ... "AS" ... "AS" ... "AS" ... "." ... "(" ... "NOT" ... "IN" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "=" ... ">" ... "<" ... "<=" ... ">=" ... "<>" ... "+" ... "-" ... "" ... "/" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "MULTISET" ... "[" ... " [SQL: u"SELECT datetime AS timestamp, COUNT() AS count \nFROM parquet_test \nWHERE datetime >= '2016-06-16 19:29:29.000000' AND datetime <= '2016-06-23 19:29:29.000000' GROUP BY datetime\n LIMIT 50000"]

in kylin sql,count and timestamp are key words,where can I change the column alias like count,timestamp,If i can do this,caravel would do ok with apache kylin.Look forward to your reply

sheweichun avatar Jun 23 '16 03:06 sheweichun

I'm not against changing these arbitrary labels, though I'm wondering if there's a way to escape them in the definition of the sqlalchemy dialect for Kylin.

For count it should be as easy as changing the metric name. For timestamp you'd have to change the source code a bit: https://github.com/airbnb/caravel/blob/master/caravel/models.py#L660 and here: https://github.com/airbnb/caravel/blob/master/caravel/models.py#L668

If you want to confirm it fixes your issue I'll be happy to review/merge the PR.

mistercrunch avatar Jun 23 '16 04:06 mistercrunch

I had fixed it before you relied me,I alias timestamp ctimestamp.but there is another issue working with kylin,quering in apache kylin,it return columns in capitals,like ctimestamp ,it will return CTIMESTAMP,then caravel will get an error ''n\ctimestamp",I fixed it in viz.py(abount line:140) `

    # The datasource here can be different backend but the interface is common
    self.results = self.datasource.query(**query_obj)
    self.query = self.results.query
    df = self.results.df
    if df is None or df.empty:
        raise Exception("No data, review your incantations!")
    else:
        dfdict = {}
        for colName in df.columns.tolist():
            dfdict[colName] = colName.lower()
        df = df.rename(index=str,columns=dfdict) 
        print("after rename1 df:",str(df.columns))
        if 'ctimestamp' in df.columns:
            df.ctimestamp = pd.to_datetime(df.ctimestamp, utc=False)
            if self.datasource.offset:
                df.ctimestamp += timedelta(hours=self.datasource.offset)
    df.replace([np.inf, -np.inf], np.nan)
    df = df.fillna(0)
    return df`

i add dfdict = {} for colName in df.columns.tolist(): dfdict[colName] = colName.lower() df = df.rename(index=str,columns=dfdict)

sheweichun avatar Jun 23 '16 10:06 sheweichun

I still have a problem,How can i add data type.Caravel support base data type,like int bigint varchar timestamp,But now I have a new data type timestamp(0),I want to know where I can map timestamp(0) to timestamp ?

sheweichun avatar Jun 24 '16 09:06 sheweichun

I also encounter the problem of timestamp(0) when connect to kylin. Do you have some way to fix this problem?

xiefan46 avatar Oct 12 '16 06:10 xiefan46

If you use pykylin, add elif type_NAME.startswith('TIMESTAMP'): args = () tpe = KYLIN_TYPE_MAP[type_NAME] in pykylin\dialect.py line:172 around

and add 'TIMESTAMP': TIMESTAMP, in types.py 's KYLIN_TYPE_MAP dict and add from sqlalchemy.types import TIMESTAMP above It should be worked.

auroralinan avatar Dec 29 '16 08:12 auroralinan

@auroralinan any chance you can open a pull request to https://github.com/wxiang7/pykylin ? There's also another messy PR regarding caravel which may have interesting fixes.

xrmx avatar Dec 29 '16 09:12 xrmx

please tell me how to connect kylin and superset

kumarit avatar Aug 04 '17 09:08 kumarit

I'm pretty sure this is fixed as we don't use timestamp as an alias anymore, we use __timestamp. Closing. @kumarit you have to connect using SQLAlchemy

mistercrunch avatar Aug 04 '17 16:08 mistercrunch

hello, anyone can help to get table /cubes from kylin into superset for visualization?? i already established the connection between kylin and superset by sqlalchemy! {"status": "failed", "query_id": 39, "error_essage": "Error when requesting: "query", exception: "Project name should not be empty.""} and to add table in a list of superset, i am getting this error, please help me Table [DEFAULT.KYLIN_SALES] could not be found, please double check your database connection, schema, and table name thanks in advance!!

kumarit avatar Aug 10 '17 11:08 kumarit