FlyingZC opened a new issue, #27684: URL: https://github.com/apache/shardingsphere/issues/27684
# Background Hi community, ShardingSphere parser engine helps users parse a SQL to get the AST (Abstract Syntax Tree) and visit this tree to get SQLStatement (Java Object). Currently, we are planning to enhance the support for openGauss SQL parsing in ShardingSphere. More details: https://shardingsphere.apache.org/document/current/en/reference/sharding/parse/ # Task This issue is to support more openGauss sql parse, as follows: ```sql #include <stdio.h> #include <stdlib.h> #include <libpq-fe.h> #include <stdint.h> static void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } static void show_binary_results(PGresult *res) { int i; int i_fnum, t_fnum; /* 使用 PQfnumber 来避免对结果中的字段顺序进行假设 */ i_fnum = PQfnumber(res, "i"); t_fnum = PQfnumber(res, "t"); for (i = 0; i < PQntuples(res); i++) { char *iptr; char *tptr; int ival; /* 获取字段值(忽略可能为空的可能) */ iptr = PQgetvalue(res, i, i_fnum); tptr = PQgetvalue(res, i, t_fnum); /* * INT4 的二进制表现形式是网络字节序 * 建议转换成本地字节序 */ ival = ntohl(*((uint32_t *) iptr)); /* * TEXT 的二进制表现形式是文本,因此libpq能够给它附加一个字节零 * 把它看做 C 字符串 * */ printf("tuple %d: got\n", i); printf(" i = (%d bytes) %d\n", PQgetlength(res, i, i_fnum), ival); printf(" t = (%d bytes) '%s'\n", PQgetlength(res, i, t_fnum), tptr); printf("\n\n"); } } int main(int argc, char **argv) { const char *conninfo; PGconn *conn; PGresult *res; const char *paramValues[1]; int paramLengths[1]; int paramFormats[1]; uint32_t binaryIntVal; if (argc > 1) conninfo = argv[1]; else conninfo = "dbname=postgres port=42121 host='10.44.133.171' application_name=test connect_timeout=5 sslmode=allow user='test' password='test_1234'"; conn = PQconnectdb(conninfo); if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); exit_nicely(conn); } /* 把整数值 "2" 转换成网络字节序 */ binaryIntVal = htonl((uint32_t) 25); /* 为 PQexecParams 设置参数数组 */ paramValues[0] = (char *) &binaryIntVal; paramLengths[0] = sizeof(binaryIntVal); paramFormats[0] = 1; /* 二进制 */ res = PQexecParams(conn, "SELECT * FROM customer_t1 WHERE c_customer_sk = $1::int4", 1, /* 一个参数 */ NULL, /* 让后端推导参数类型 */ paramValues, paramLengths, paramFormats, 1); /* 要求二进制结果 */ if (PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } show_binary_results(res); PQclear(res); /* 关闭与数据库的连接并清理 */ PQfinish(conn); return 0; ``` ```sql #include <stdio.h> #include <stdlib.h> #include <libpq-fe.h> static void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } int main(int argc, char **argv) { const char *conninfo; PGconn *conn; PGresult *res; int nFields; int i,j; if (argc > 1) conninfo = argv[1]; else conninfo = "dbname=postgres port=42121 host='10.44.133.171' application_name=test connect_timeout=5 sslmode=allow user='test' password='test_1234'"; conn = PQconnectdb(conninfo); if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); exit_nicely(conn); } res = PQexec(conn, "update customer_t1 set c_customer_sk = 1000 where c_customer_name = 'li'"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "UPDATE command failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } /* 关闭数据库连接并清理 */ PQfinish(conn); return 0; ``` ```sql #include <stdio.h> #include <stdlib.h> #include <libpq-fe.h> static void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } int main(int argc, char **argv) { const char *conninfo; PGconn *conn; PGresult *res; int nFields; int i,j; if (argc > 1) conninfo = argv[1]; else conninfo = "dbname=postgres port=42121 host='10.44.133.171' application_name=test connect_timeout=5 sslmode=allow user='test' password='test_1234'"; conn = PQconnectdb(conninfo); if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); exit_nicely(conn); } res = PQexec(conn, "delete from customer_t1 where c_customer_name = 'li"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "DELETE command failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } /* 关闭数据库连接并清理 */ PQfinish(conn); return 0; ``` ```sql SQLRETURN SQLSetStmtAttr(SQLHSTMT StatementHandle SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER StringLength); ``` ```sql python >>> import base64 >>> print base64.b64encode("XXXXXXXXX"); ``` # Process 1. First confirm that this is a correct openGauss sql syntax, if not please leave a message under the issue and ignore it; 2. Compare SQL definitions in Official SQL Doc and ShardingSphere SQL Doc; 3. If there is any difference in ShardingSphere SQL Doc, please correct them by referring to the Official SQL Doc; 4. Run mvn install the current_file_module; 5. Check whether there are any exceptions. If indeed, please fix them. (Especially xxxVisitor.class); 6. Add new corresponding SQL case in SQL Cases and expected parsed result in Expected Statement XML; 7. Run SQLParserParameterizedTest to make sure no exceptions. # Relevant Skills 1. Master JAVA language 2. Have a basic understanding of Antlr `g4` file 3. Be familiar with openGauss SQLs -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
