# Buggy code
def _get_selectable(self, engine_or_conn, columns=None):
    import sqlalchemy as sa
    from sqlalchemy import sql
    from sqlalchemy.exc import NoSuchTableError

    # process table_name
    if self._selectable is not None:
        selectable = self._selectable
    else:
        if isinstance(self._table_or_sql, sa.Table):
            selectable = self._table_or_sql
            self._table_or_sql = selectable.name
        else:
            m = sa.MetaData()
            try:
                selectable = sa.Table(
                    self._table_or_sql,
                    m,
                    autoload=True,
                    autoload_with=engine_or_conn,
                    schema=self._schema,
                )
            except NoSuchTableError:
                temp_table_name = (
                    "temp_" + binascii.b2a_hex(uuid.uuid4().bytes).decode()
                )
                if columns:
                    selectable = sql.text(self._table_or_sql).columns(
                        *[sql.column(c) for c in columns]
                    )
                else:
                    selectable = sql.select(
                        "*",
                        from_obj=sql.text(
                            "(%s) AS %s" % (self._table_or_sql, temp_table_name)
                        ),
                    )
                self._selectable = selectable
    return selectable


# Traceback (mysql.connector.errors.ProgrammingError)
Traceback (most recent call last):
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 1249, in _execute_context
cursor, statement, parameters, context
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\default.py", line 580, in do_execute
cursor.execute(statement, parameters)
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\cursor.py", line 551, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\connection.py", line 490, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1248 (42000): Every derived table must have its own alias

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "E:\mycodes\readdatabymars.py", line 17, in <module>
df = md.read_sql_query(sql1, con=engine)
File "D:\Anaconda3\envs\py37\lib\site-packages\mars\dataframe\datasource\read_sql.py", line 766, in read_sql_query
low_limit=low_limit, high_limit=high_limit)
File "D:\Anaconda3\envs\py37\lib\site-packages\mars\dataframe\datasource\read_sql.py", line 476, in _read_sql
return op(test_rows, chunk_size)
File "D:\Anaconda3\envs\py37\lib\site-packages\mars\dataframe\datasource\read_sql.py", line 250, in __call__
test_df, shape = self._collect_info(con, selectable, collect_cols, test_rows)
File "D:\Anaconda3\envs\py37\lib\site-packages\mars\dataframe\datasource\read_sql.py", line 196, in _collect_info
parse_dates=self._parse_dates)
File "D:\Anaconda3\envs\py37\lib\site-packages\pandas\io\sql.py", line 436, in read_sql
chunksize=chunksize,
File "D:\Anaconda3\envs\py37\lib\site-packages\pandas\io\sql.py", line 1218, in read_query
result = self.execute(*args)
File "D:\Anaconda3\envs\py37\lib\site-packages\pandas\io\sql.py", line 1087, in execute
return self.connectable.execute(*args, **kwargs)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 988, in execute
return meth(self, multiparams, params)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\sql\elements.py", line 287, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 1107, in _execute_clauseelement
distilled_params,
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 1253, in _execute_context
e, statement, parameters, cursor, context
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 1473, in _handle_dbapi_exception
util.raise_from_cause(sqlalchemy_exception, exc_info)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\util\compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\util\compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\base.py", line 1249, in _execute_context
cursor, statement, parameters, context
File "D:\Anaconda3\envs\py37\lib\site-packages\sqlalchemy\engine\default.py", line 580, in do_execute
cursor.execute(statement, parameters)
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\cursor.py", line 551, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\connection.py", line 490, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "D:\Anaconda3\envs\py37\lib\site-packages\mysql\connector\connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1248 (42000): Every derived table must have its own alias
[SQL: SELECT *
FROM (SELECT *
FROM (SELECT * FROM  table1) AS temp_6302b78c8a9347b8b02475d757cf17f7)
LIMIT %(param_1)s]
[parameters: {'param_1': 5}]
(Background on this error at: http://sqlalche.me/e/f405)

# Fixed code
def _get_selectable(self, engine_or_conn, columns=None):
    import sqlalchemy as sa
    from sqlalchemy import sql
    from sqlalchemy.exc import NoSuchTableError

    # process table_name
    if self._selectable is not None:
        selectable = self._selectable
    else:
        if isinstance(self._table_or_sql, sa.Table):
            selectable = self._table_or_sql
            self._table_or_sql = selectable.name
        else:
            m = sa.MetaData()
            try:
                selectable = sa.Table(
                    self._table_or_sql,
                    m,
                    autoload=True,
                    autoload_with=engine_or_conn,
                    schema=self._schema,
                )
            except NoSuchTableError:
                temp_name_1 = "t1_" + binascii.b2a_hex(uuid.uuid4().bytes).decode()
                temp_name_2 = "t2_" + binascii.b2a_hex(uuid.uuid4().bytes).decode()
                if columns:
                    selectable = (
                        sql.text(self._table_or_sql)
                        .columns(*[sql.column(c) for c in columns])
                        .alias(temp_name_2)
                    )
                else:
                    selectable = sql.select(
                        "*",
                        from_obj=sql.text(
                            "(%s) AS %s" % (self._table_or_sql, temp_name_1)
                        ),
                    ).alias(temp_name_2)
                self._selectable = selectable
    return selectable