Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions client-v2/src/main/java/com/clickhouse/client/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,9 @@ record = allocator == null ? clazz.getDeclaredConstructor().newInstance() : allo
/**
* <p>Fetches schema of a table and returns complete information about each column.
* Information includes column name, type, default value, etc.</p>
* <p>Important: table name should be properly escaped
* (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)).
* This method uses table name as is because method is not aware if database name also present and cannot properly escape it.</p>
*
* <p>See {@link #register(Class, TableSchema)}</p>
*
Expand All @@ -2304,6 +2307,9 @@ public TableSchema getTableSchema(String table) {
* <p>Fetches schema of a table and returns complete information about each column.
* Information includes column name, type, default value, etc.</p>
* <p>See {@link #register(Class, TableSchema)}</p>
* <p>Important: table name should be properly escaped
* (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean))
* and should not contain database name</p>
*
* @param table - table name
* @param database - database name
Expand All @@ -2316,13 +2322,25 @@ public TableSchema getTableSchema(String table, String database) {

/**
* <p>Creates table schema from a query.</p>
* <p>Important: table name should be properly escaped
* (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)).
* This method doesn't validate or parse the SQL query</p>
* @param sql - SQL query which schema to return
* @return table schema for the query
*/
public TableSchema getTableSchemaFromQuery(String sql) {
return getTableSchemaFromQuery(sql, null);
}

/**
* <p>Creates table schema from a query.</p>
* <p>Important: table name should be properly escaped
* (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)).
* This method doesn't validate or parse the SQL query</p>
* @param sql - SQL query which schema to return
* @param params - server bound parameters
* @return table schema for the query
*/
public TableSchema getTableSchemaFromQuery(String sql, Map<String, Object> params) {
final String describeQuery = "DESC (" + sql + ")";
return getTableSchemaImpl(describeQuery, null, sql, getDefaultDatabase(), params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class SQLUtils {
/**
* Escapes and quotes a string literal for use in SQL queries.
* ClickHouse honours backslash escape sequences inside single-quoted strings, so a backslash
* ClickHouse honors backslash escape sequences inside single-quoted strings, so a backslash
* is escaped by doubling it before the single quotes are doubled. Without that, a literal
* backslash-t in the input would reach the server as a TAB, and a trailing backslash would
* escape the closing quote.
Expand Down
Loading