为什么对Impala进行的这种运行良好的查询会通过ODBC驱动程序引发错误?

时间:2018-12-28 13:26:37

标签: c# odbc impala

我有下面的查询,该查询在Hue中运行完美,但通过C#的ODBC失败。 ODBC驱动程序说了一些有关未知参数的内容,但是我不知道那是什么。在日志中,^指向关键字LIMIT之后的问号。我不得不修改日志中的查询以隐藏详细信息。

基于日志,似乎查询到达了Impala,并且Impala引发错误,而不是驱动程序。如果为真,那么为什么从Hue可以使用相同的查询? (这意味着我将selectCommand.CommandText复制粘贴到Hue,并将问号替换为与查询和执行中使用的数字相同的数字。

另一方面,同一应用程序具有查询,其中ODBC驱动程序使用问号格式将查询放在一起,并且像超级按钮一样工作。

我没办法做些什么。任何帮助将不胜感激。

查询

SELECT
  -- list of fields comma separated 
FROM tableName 
ORDER BY oneOfTheFields 
LIMIT ? 
OFFSET ?

C#代码:

public async Task<List<ClusterMetadataIEdhEntity>> GetAllOffSetted(int limit, int offset)
{
    if (limit == 0)
    {
        throw new ArgumentNullException();
    }

    List<ClusterMetadataIEdhEntity> result = new List<ClusterMetadataIEdhEntity>();

    string select = $"SELECT " +
                    $"{someFieldName}, " +
                    $"{anotherFieldName} " +
                    $"FROM {tableName} " +
                    $"ORDER BY {colId} " +
                    $"LIMIT ? " +
                    $"OFFSET ?";

    using (OdbcCommand selectCommand = new OdbcCommand(select, odbcConnection))
    {
        selectCommand.Parameters.Add("@limit", OdbcType.Int).Value = limit;
        selectCommand.Parameters.Add("@offset", OdbcType.Int).Value = offset;

        Console.WriteLine(selectCommand.CommandText);
        DbDataReader reader = await selectCommand.ExecuteReaderAsync();
    }

ODBC 驱动程序日志:

Dec 28 13:55:49.179 TRACE 775 Connection::SQLGetFunctions: +++++ enter +++++
Dec 28 13:55:49.179 TRACE 775 ConnectionState::SQLGetFunctions: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 Connection::SQLAllocHandle: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 ConnectionState4::SQLAllocHandle: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 ConnectionState::SQLAllocHandle: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 ImpalaConnection::CreateStatement: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 ImpalaStatement::ImpalaStatement: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 Statement::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.217 INFO  775 Statement::SQLGetStmtAttrW: Attribute: SQL_ATTR_APP_ROW_DESC (10010)
Dec 28 13:55:49.217 TRACE 775 StatementStateAllocated::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.217 TRACE 775 StatementState::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 Statement::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 INFO  775 Statement::SQLGetStmtAttrW: Attribute: SQL_ATTR_APP_PARAM_DESC (10011)
Dec 28 13:55:49.218 TRACE 775 StatementStateAllocated::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 StatementState::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 Statement::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 INFO  775 Statement::SQLGetStmtAttrW: Attribute: SQL_ATTR_IMP_ROW_DESC (10012)
Dec 28 13:55:49.218 TRACE 775 StatementStateAllocated::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 StatementState::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 Statement::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 INFO  775 Statement::SQLGetStmtAttrW: Attribute: SQL_ATTR_IMP_PARAM_DESC (10013)
Dec 28 13:55:49.218 TRACE 775 StatementStateAllocated::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.218 TRACE 775 StatementState::SQLGetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.219 TRACE 775 Statement::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.219 INFO  775 Statement::SQLSetStmtAttrW: Attribute: SQL_ATTR_QUERY_TIMEOUT (0)
Dec 28 13:55:49.219 TRACE 775 StatementState::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.219 TRACE 775 StatementAttributes::SetAttribute: +++++ enter +++++
Dec 28 13:55:49.222 TRACE 775 Connection::SQLGetInfoW: +++++ enter +++++
Dec 28 13:55:49.222 INFO  775 Connection::SQLGetInfoW: InfoType: SQL_DRIVER_ODBC_VER (77)
Dec 28 13:55:49.222 TRACE 775 Statement::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.222 INFO  775 Statement::SQLSetStmtAttrW: Attribute: Unknown Attribute (1228)
Dec 28 13:55:49.222 TRACE 775 StatementState::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.222 TRACE 775 StatementAttributes::SetAttribute: +++++ enter +++++
Dec 28 13:55:49.222 INFO  775 StatementAttributes::SetAttribute: Invalid attribute: 1228
Dec 28 13:55:49.223 ERROR 775 Statement::SQLSetStmtAttrW: [Cloudera][ODBC] (10210) Attribute identifier invalid or not supported: 1228
Dec 28 13:55:49.226 TRACE 775 Statement::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.226 INFO  775 Statement::SQLSetStmtAttrW: Attribute: Unknown Attribute (1227)
Dec 28 13:55:49.226 TRACE 775 StatementState::SQLSetStmtAttrW: +++++ enter +++++
Dec 28 13:55:49.226 TRACE 775 StatementAttributes::SetAttribute: +++++ enter +++++
Dec 28 13:55:49.226 INFO  775 StatementAttributes::SetAttribute: Invalid attribute: 1227
Dec 28 13:55:49.226 ERROR 775 Statement::SQLSetStmtAttrW: [Cloudera][ODBC] (10210) Attribute identifier invalid or not supported: 1227
Dec 28 13:55:49.246 TRACE 775 Statement::SQLBindParameter: +++++ enter +++++
Dec 28 13:55:49.246 TRACE 775 StatementState::SQLBindParameter: +++++ enter +++++
Dec 28 13:55:49.246 TRACE 775 Statement::SQLBindParameter: +++++ enter +++++
Dec 28 13:55:49.246 TRACE 775 StatementState::SQLBindParameter: +++++ enter +++++
Dec 28 13:55:49.247 TRACE 775 Connection::SQLExecDirectW: +++++ enter +++++
Dec 28 13:55:49.247 TRACE 775 ConnectionState5::SQLExecDirectW: +++++ enter +++++
Dec 28 13:55:49.247 TRACE 775 ConnectionState::SQLExecDirectW: +++++ enter +++++
Dec 28 13:55:49.247 TRACE 775 Statement::SQLExectDirectW: +++++ enter +++++
Dec 28 13:55:49.247 TRACE 775 StatementStateAllocated::SQLExecDirectW: +++++ enter +++++
Dec 28 13:55:49.247 INFO  775 StatementState::InternalPrepare: Preparing query: SELECT fields FROM table ORDER BY id LIMIT ? OFFSET ?
Dec 28 13:55:49.247 TRACE 775 ImpalaStatement::CreateDataEngine: +++++ enter +++++
Dec 28 13:55:49.248 TRACE 775 ImpalaDataEngine::ImpalaDataEngine: +++++ enter +++++
Dec 28 13:55:49.248 TRACE 775 ImpalaDataEngine::Prepare: +++++ enter +++++
Dec 28 13:55:49.251 INFO  775 ImpalaDataEngine::Prepare: Trying to parse query: SELECT fields FROM table ORDER BY id LIMIT ? OFFSET ?
Dec 28 13:55:49.254 INFO  775 ImpalaDataEngine::Prepare: [Cloudera][SQLEngine] (31480) syntax error near 'SELECT fields FROM table ORDER BY id LIMIT ? OFFSET<<< ??? >>> ?'.
Dec 28 13:55:49.254 TRACE 775 ImpalaClient::IsNullCellInfosRequired: +++++ enter +++++
Dec 28 13:55:49.254 TRACE 775 ImpalaResultSet::ImpalaResultSet: +++++ enter +++++
Dec 28 13:55:49.254 TRACE 775 ImpalaNativeQueryExecutor::Execute: +++++ enter +++++
Dec 28 13:55:49.254 TRACE 775 ImpalaClient::ExecuteStatement: +++++ enter +++++
Dec 28 13:55:49.254 TRACE 775 ImpalaClient::ExecuteStatementInternal: +++++ enter +++++
Dec 28 13:55:49.254 DEBUG 775 ImpalaTCLIServiceThreadSafeClient::ExecuteStatement: TExecuteStatementReq
    sessionHandle.sessionId.guid = be2667f4506840daaba657ad40304f53
    statement = SELECT fields FROM table ORDER BY id LIMIT ? OFFSET ?
    runAsync = true
Dec 28 13:55:49.254 TRACE 775 ImpalaTCLIServiceThreadSafeClient::ExecuteStatement: +++++ enter +++++
Dec 28 13:55:49.474 TRACE 775 ImpalaTCLIServiceThreadSafeClient::ExecuteStatement: +++++ leave +++++
Dec 28 13:55:49.475 ERROR 775 QueryExecutor::Execute: [Cloudera][ImpalaODBC] (110) Error while executing a query in Impala: [HY000] : AnalysisException: Syntax error in line 1:
... ORDER BY id LIMIT ? OFFSET ?
                             ^
Encountered: Unexpected character
Expected: CASE, CAST, DEFAULT, EXISTS, FALSE, IF, INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, TRUNCATE, TRUE, IDENTIFIER

0 个答案:

没有答案