IBM-Cloud / sql-query-clients

Client samples for IBM Cloud SQL Query service
Apache License 2.0
12 stars 24 forks source link

sqlquery in watson jupyter notebook fail #136

Open powellquiring opened 2 years ago

powellquiring commented 2 years ago

When this code is run in a jupyter notebook I get the following error. Help, please help me find the right team.

The error message is something about the vpc images that are in my account - crazy

Thanks.

Notebook: https://github.com/powellquiring/log-archive/blob/master/logarchive.ipynb

apikeys are not valid

Your SQL statement is:

SELECT YEAR,
    MONTH,
    _source__line
FROM FLATTEN(cos://s3.us-south.cloud-OBJECT-storage.appdomain.cloud/logarchive-001 STORED AS JSON)
WHERE _source_outcome NOT REGEXP "success"
LIMIT 10 INTO cos://s3.us-south.cloud-OBJECT-storage.appdomain.cloud/logarchive-DATA-ENGINE-001 STORED AS JSON

SELECT year, month, _source__line FROM FLATTEN(cos://s3.us-south.cloud-object-storage.appdomain.cloud/logarchive-001 STORED AS JSON) WHERE _source_outcome NOT REGEXP "success" LIMIT 10 INTO cos://s3.us-south.cloud-object-storage.appdomain.cloud/logarchive-data-engine-001 STORED AS JSON
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/wsuser/ipykernel_132/1620942991.py in <module>
----> 1 result_df = sql_r(f'SELECT year, month, _source__line FROM FLATTEN({logsurl} STORED AS JSON) WHERE _source_outcome NOT REGEXP "success" LIMIT 10')

/tmp/wsuser/ipykernel_132/3763084951.py in sql_r(sql)
     17     sql_format_print(sql)
     18     print(sql)
---> 19     result_df = sqlClient.run_sql(sql)
     20     # print(result_df.head(10))
     21     return result_df

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/ibmcloudsql/SQLQuery.py in run_sql(self, sql_text, pagesize)
   1683                 pprint.pprint(details)
   1684                 raise e
-> 1685         return self.get_result(job_id)
   1686 
   1687     def run(self, pagesize=None, get_result=False):

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/ibmcloudsql/SQLQuery.py in get_result(self, jobId, pagenumber)
    977                     body = body.read().decode("utf-8")
    978 
--> 979                     partition_df = pd.read_json(body, lines=True)
    980 
    981                 # Add columns from hive style partition naming schema

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    205                 else:
    206                     kwargs[new_arg_name] = new_arg_value
--> 207             return func(*args, **kwargs)
    208 
    209         return cast(F, wrapper)

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    309                     stacklevel=stacklevel,
    310                 )
--> 311             return func(*args, **kwargs)
    312 
    313         return wrapper

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/io/json/_json.py in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, encoding_errors, lines, chunksize, compression, nrows, storage_options)
    588         convert_axes = True
    589 
--> 590     json_reader = JsonReader(
    591         path_or_buf,
    592         orient=orient,

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/io/json/_json.py in __init__(self, filepath_or_buffer, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, lines, chunksize, compression, nrows, storage_options, encoding_errors)
    673                 raise ValueError("nrows can only be passed if lines=True")
    674 
--> 675         data = self._get_data_from_filepath(filepath_or_buffer)
    676         self.data = self._preprocess_data(data)
    677 

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/io/json/_json.py in _get_data_from_filepath(self, filepath_or_buffer)
    710             or file_exists(filepath_or_buffer)
    711         ):
--> 712             self.handles = get_handle(
    713                 filepath_or_buffer,
    714                 "r",

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/io/common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    607 
    608     # open URLs
--> 609     ioargs = _get_filepath_or_buffer(
    610         path_or_buf,
    611         encoding=encoding,

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/pandas/io/common.py in _get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode, storage_options)
    356 
    357         try:
--> 358             file_obj = fsspec.open(
    359                 filepath_or_buffer, mode=fsspec_mode, **(storage_options or {})
    360             ).open()

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in open(urlpath, mode, compression, encoding, errors, protocol, newline, **kwargs)
    450     ``OpenFile`` object.
    451     """
--> 452     return open_files(
    453         urlpath=[urlpath],
    454         mode=mode,

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in open_files(urlpath, mode, compression, encoding, errors, name_function, num, protocol, newline, auto_mkdir, expand, **kwargs)
    284     be used as a single context
    285     """
--> 286     fs, fs_token, paths = get_fs_token_paths(
    287         urlpath,
    288         mode,

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in get_fs_token_paths(urlpath, mode, num, name_function, storage_options, protocol, expand)
    592     else:
    593         urlpath = stringify_path(urlpath)
--> 594     chain = _un_chain(urlpath, storage_options or {})
    595     if len(chain) > 1:
    596         inkwargs = {}

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in _un_chain(path, kwargs)
    316 def _un_chain(path, kwargs):
    317     if isinstance(path, (tuple, list)):
--> 318         bits = [_un_chain(p, kwargs) for p in path]
    319         out = []
    320         for pbit in zip(*bits):

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in <listcomp>(.0)
    316 def _un_chain(path, kwargs):
    317     if isinstance(path, (tuple, list)):
--> 318         bits = [_un_chain(p, kwargs) for p in path]
    319         out = []
    320         for pbit in zip(*bits):

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/core.py in _un_chain(path, kwargs)
    341     for bit in reversed(bits):
    342         protocol = split_protocol(bit)[0] or "file"
--> 343         cls = get_filesystem_class(protocol)
    344         extra_kwargs = cls._get_kwargs_from_urls(bit)
    345         kws = kwargs.get(protocol, {})

/opt/conda/envs/Python-3.9/lib/python3.9/site-packages/fsspec/registry.py in get_filesystem_class(protocol)
    214     if protocol not in registry:
    215         if protocol not in known_implementations:
--> 216             raise ValueError("Protocol not known: %s" % protocol)
    217         bit = known_implementations[protocol]
    218         try:

ValueError: Protocol not known: image:r006-774b8de7-3d9a-4692-bb36-157c710b804a\",\"typeURI\":\"is.image/image\",\"name\":\"usc4-travis-72589103\",\"host\":{\"address\":\"https