Skip to content

Commit

Permalink
Merge pull request ydb-platform#24 from alex268/develop
Browse files Browse the repository at this point in the history
Remove obsolete parameters
  • Loading branch information
alex268 authored Sep 29, 2023
2 parents be33be2 + 33646ae commit c10fdf0
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 85 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 2.0.2 ##

* Removed obsolete options

## 2.0.1 ##

* Added column types to getTables() method
* Added column tables to getTables() method
* Added parameter `forceQueryMode` to use for specifying the type of query
* Execution of scan or scheme query inside active transaction will raise exception
* Execution of scan or scheme query inside active transaction will throw exception

## 2.0.0 ##

Expand Down
2 changes: 1 addition & 1 deletion jdbc-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>tech.ydb.jdbc</groupId>
<artifactId>ydb-jdbc-driver-parent</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>

<artifactId>ydb-jdbc-driver-shaded</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>tech.ydb.jdbc</groupId>
<artifactId>ydb-jdbc-driver-parent</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>

<artifactId>ydb-jdbc-driver</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions jdbc/src/main/java/tech/ydb/jdbc/YdbConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ public final class YdbConst {
*/
public static final int STALE_CONSISTENT_READ_ONLY = 3; // TODO: verify if we can do that

public static final int DEFAULT_JDBC_SUPPORT_LEVEL = 5;

// Processing queries
public static final String PREFIX_SYNTAX_V1 = "--!syntax_v1";

public static final String EXPLAIN_COLUMN_AST = "AST";
public static final String EXPLAIN_COLUMN_PLAN = "PLAN";

Expand Down
7 changes: 0 additions & 7 deletions jdbc/src/main/java/tech/ydb/jdbc/query/YdbQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ public List<String> getIndexesParameters() {
public String getYqlQuery(Params params) throws SQLException {
StringBuilder yql = new StringBuilder();

if (opts.isEnforceSyntaxV1()) {
if (!yqlQuery.startsWith(YdbConst.PREFIX_SYNTAX_V1)) {
yql.append(YdbConst.PREFIX_SYNTAX_V1);
yql.append("\n");
}
}

if (indexesArgsNames != null) {
if (params != null) {
Map<String, Value<?>> values = params.values();
Expand Down
26 changes: 5 additions & 21 deletions jdbc/src/main/java/tech/ydb/jdbc/query/YdbQueryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @author Aleksandr Gorshenin
*/
public class YdbQueryOptions {
private final boolean isEnforceSyntaxV1;

private final boolean isDetectQueryType;
private final boolean isDetectJdbcParameters;
private final boolean isDeclareJdbcParameters;
Expand All @@ -27,16 +25,13 @@ public class YdbQueryOptions {

@VisibleForTesting
YdbQueryOptions(
boolean enforceV1,
boolean detectQueryType,
boolean detectJbdcParams,
boolean declareJdbcParams,
boolean prepareDataQuery,
boolean detectBatchQuery,
QueryType forcedType
) {
this.isEnforceSyntaxV1 = enforceV1;

this.isDetectQueryType = detectQueryType;
this.isDetectJdbcParameters = detectJbdcParams;
this.isDeclareJdbcParameters = declareJdbcParams;
Expand All @@ -47,10 +42,6 @@ public class YdbQueryOptions {
this.forcedType = forcedType;
}

public boolean isEnforceSyntaxV1() {
return isEnforceSyntaxV1;
}

public boolean isDetectQueryType() {
return isDetectQueryType;
}
Expand All @@ -76,20 +67,14 @@ public QueryType getForcedQueryType() {
}

public static YdbQueryOptions createFrom(YdbOperationProperties props) {
int level = props.getJdbcSupportLevel();

boolean enforceV1 = level > 5;
boolean declareJdbcParams = level > 4;
boolean detectJbdcParams = level > 3;
boolean detectBatchQuery = level > 2;
boolean prepareDataQuery = level > 1;
boolean detectQueryType = level > 0;
boolean declareJdbcParams = true;
boolean detectJbdcParams = true;
boolean detectBatchQuery = true;
boolean prepareDataQuery = true;
boolean detectQueryType = true;

// forced properies
Map<YdbOperationProperty<?>, ParsedProperty> params = props.getParams();
if (params.containsKey(YdbOperationProperty.ENFORCE_SQL_V1)) {
enforceV1 = params.get(YdbOperationProperty.ENFORCE_SQL_V1).getParsedValue();
}

if (params.containsKey(YdbOperationProperty.DISABLE_AUTO_PREPARED_BATCHES)) {
boolean v = params.get(YdbOperationProperty.DISABLE_AUTO_PREPARED_BATCHES).getParsedValue();
Expand Down Expand Up @@ -123,7 +108,6 @@ public static YdbQueryOptions createFrom(YdbOperationProperties props) {
QueryType forcedQueryType = props.getForcedQueryType();

return new YdbQueryOptions(
enforceV1,
detectQueryType,
detectJbdcParams,
declareJdbcParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class YdbOperationProperties {
private final int maxRows;
private final boolean cacheConnectionsInDriver;

private final int jdbcSupportLevel;

private final FakeTxMode scanQueryTxMode;
private final FakeTxMode schemeQueryTxMode;
private final QueryType forcedQueryType;
Expand All @@ -41,8 +39,6 @@ public YdbOperationProperties(Map<YdbOperationProperty<?>, ParsedProperty> param
this.maxRows = MAX_ROWS;
this.cacheConnectionsInDriver = params.get(YdbOperationProperty.CACHE_CONNECTIONS_IN_DRIVER).getParsedValue();

this.jdbcSupportLevel = params.get(YdbOperationProperty.JDBC_SUPPORT_LEVEL).getParsedValue();

this.scanQueryTxMode = params.get(YdbOperationProperty.SCAN_QUERY_TX_MODE).getParsedValue();
this.schemeQueryTxMode = params.get(YdbOperationProperty.SCHEME_QUERY_TX_MODE).getParsedValue();

Expand Down Expand Up @@ -105,8 +101,4 @@ public int getMaxRows() {
public boolean isCacheConnectionsInDriver() {
return cacheConnectionsInDriver;
}

public int getJdbcSupportLevel() {
return jdbcSupportLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import javax.annotation.Nullable;

import tech.ydb.jdbc.YdbConst;
import tech.ydb.jdbc.query.QueryType;


Expand Down Expand Up @@ -89,13 +88,6 @@ public class YdbOperationProperty<T> extends AbstractYdbProperty<T, Void> {
PropertyConverter.booleanValue());


public static final YdbOperationProperty<Boolean> ENFORCE_SQL_V1 =
new YdbOperationProperty<>("enforceSqlV1",
"Enforce SQL v1 grammar by adding --!syntax_v1 in the beginning of each SQL statement",
"false",
Boolean.class,
PropertyConverter.booleanValue());

public static final YdbOperationProperty<Boolean> DISABLE_DETECT_SQL_OPERATIONS =
new YdbOperationProperty<>("disableDetectSqlOperations",
"Disable detecting SQL operation based on SQL keywords",
Expand Down Expand Up @@ -132,13 +124,6 @@ public class YdbOperationProperty<T> extends AbstractYdbProperty<T, Void> {
Boolean.class,
PropertyConverter.booleanValue());

public static final YdbOperationProperty<Integer> JDBC_SUPPORT_LEVEL =
new YdbOperationProperty<>("jdbcSupportLevel",
"Disable auto detect JDBC standart parameters '?'",
"" + YdbConst.DEFAULT_JDBC_SUPPORT_LEVEL,
Integer.class,
PropertyConverter.integerValue());

public static final YdbOperationProperty<FakeTxMode> SCAN_QUERY_TX_MODE =
new YdbOperationProperty<>("scanQueryTxMode",
"Mode of execution scan query inside transaction. "
Expand Down
10 changes: 0 additions & 10 deletions jdbc/src/test/java/tech/ydb/jdbc/YdbDriverProperitesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,12 @@ static DriverPropertyInfo[] defaultPropertyInfo(@Nullable String localDatacenter

YdbOperationProperty.CACHE_CONNECTIONS_IN_DRIVER.toDriverPropertyInfo("true"),

YdbOperationProperty.ENFORCE_SQL_V1.toDriverPropertyInfo("false"),

YdbOperationProperty.DISABLE_DETECT_SQL_OPERATIONS.toDriverPropertyInfo("false"),
YdbOperationProperty.DISABLE_PREPARE_DATAQUERY.toDriverPropertyInfo("false"),
YdbOperationProperty.DISABLE_AUTO_PREPARED_BATCHES.toDriverPropertyInfo("false"),
YdbOperationProperty.DISABLE_JDBC_PARAMETERS.toDriverPropertyInfo("false"),
YdbOperationProperty.DISABLE_JDBC_PARAMETERS_DECLARE.toDriverPropertyInfo("false"),

YdbOperationProperty.JDBC_SUPPORT_LEVEL.toDriverPropertyInfo("" + YdbConst.DEFAULT_JDBC_SUPPORT_LEVEL),

YdbOperationProperty.SCAN_QUERY_TX_MODE.toDriverPropertyInfo("ERROR"),
YdbOperationProperty.SCHEME_QUERY_TX_MODE.toDriverPropertyInfo("ERROR"),
YdbOperationProperty.FORCE_QUERY_MODE.toDriverPropertyInfo(null),
Expand Down Expand Up @@ -368,13 +364,11 @@ static Properties customizedProperties() {

properties.setProperty("cacheConnectionsInDriver", "false");

properties.setProperty("enforceSqlV1", "true");
properties.setProperty("disablePrepareDataQuery", "true");
properties.setProperty("disableAutoPreparedBatches", "true");
properties.setProperty("disableDetectSqlOperations", "true");
properties.setProperty("disableJdbcParameters", "true");
properties.setProperty("disableJdbcParameterDeclare", "true");
properties.setProperty("jdbcSupportLevel", "0");

properties.setProperty("scanQueryTxMode", "FAKE_TX");
properties.setProperty("schemeQueryTxMode", "SHADOW_COMMIT");
Expand Down Expand Up @@ -410,15 +404,12 @@ static DriverPropertyInfo[] customizedPropertyInfo() {

YdbOperationProperty.CACHE_CONNECTIONS_IN_DRIVER.toDriverPropertyInfo("false"),

YdbOperationProperty.ENFORCE_SQL_V1.toDriverPropertyInfo("true"),
YdbOperationProperty.DISABLE_DETECT_SQL_OPERATIONS.toDriverPropertyInfo("true"),
YdbOperationProperty.DISABLE_PREPARE_DATAQUERY.toDriverPropertyInfo("true"),
YdbOperationProperty.DISABLE_AUTO_PREPARED_BATCHES.toDriverPropertyInfo("true"),
YdbOperationProperty.DISABLE_JDBC_PARAMETERS.toDriverPropertyInfo("true"),
YdbOperationProperty.DISABLE_JDBC_PARAMETERS_DECLARE.toDriverPropertyInfo("true"),

YdbOperationProperty.JDBC_SUPPORT_LEVEL.toDriverPropertyInfo("0"),

YdbOperationProperty.SCAN_QUERY_TX_MODE.toDriverPropertyInfo("FAKE_TX"),
YdbOperationProperty.SCHEME_QUERY_TX_MODE.toDriverPropertyInfo("SHADOW_COMMIT"),
YdbOperationProperty.FORCE_QUERY_MODE.toDriverPropertyInfo("SCAN_QUERY"),
Expand All @@ -439,7 +430,6 @@ static void checkCustomizedProperties(YdbProperties properties) {
Assertions.assertTrue(ops.isAutoCommit());
Assertions.assertEquals(YdbConst.ONLINE_CONSISTENT_READ_ONLY, ops.getTransactionLevel());
Assertions.assertFalse(ops.isCacheConnectionsInDriver());
Assertions.assertEquals(0, ops.getJdbcSupportLevel());
}

static String asString(DriverPropertyInfo info) {
Expand Down
18 changes: 3 additions & 15 deletions jdbc/src/test/java/tech/ydb/jdbc/query/QueryLexerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,9 @@ private void assertMixType(YdbQueryOptions opts, String types, String sql) {
Assertions.assertEquals("Query cannot contain expressions with different types: " + types, ex.getMessage());
}

@Test
public void enforceV1Test() throws SQLException {
YdbQueryOptions disabled = new YdbQueryOptions(false, true, true, true, true, true, null);
YdbQueryOptions enabled = new YdbQueryOptions(true, true, true, true, true, true, null);

Assertions.assertEquals("CREATE TABLE test_table (id int, value text)",
parseQuery(disabled, "CREATE TABLE test_table (id int, value text)"));

Assertions.assertEquals("--!syntax_v1\nCREATE TABLE test_table (id int, value text)",
parseQuery(enabled, "CREATE TABLE test_table (id int, value text)"));
}

@Test
public void queryTypesTest() throws SQLException {
YdbQueryOptions opts = new YdbQueryOptions(false, true, false, false, false, false, null);
YdbQueryOptions opts = new YdbQueryOptions(true, false, false, false, false, null);

Assertions.assertEquals(QueryType.SCHEME_QUERY, parseQueryType(opts,
"CREATE TABLE test_table (id int, value text)"
Expand Down Expand Up @@ -89,7 +77,7 @@ public void queryTypesTest() throws SQLException {

@Test
public void mixQueryExceptionTest() throws SQLException {
YdbQueryOptions opts = new YdbQueryOptions(false, true, false, false, false, false, null);
YdbQueryOptions opts = new YdbQueryOptions(true, false, false, false, false, null);

assertMixType(opts, "SCHEME_QUERY, DATA_QUERY",
"CREATE TABLE test_table (id int, value text);" +
Expand All @@ -111,7 +99,7 @@ public void mixQueryExceptionTest() throws SQLException {

@Test
public void forsedTypeTest() throws SQLException {
YdbQueryOptions opts = new YdbQueryOptions(false, true, false, false, false, false, QueryType.SCHEME_QUERY);
YdbQueryOptions opts = new YdbQueryOptions(true, false, false, false, false, QueryType.SCHEME_QUERY);

Assertions.assertEquals(QueryType.SCHEME_QUERY, parseQueryType(opts,
"CREATE TABLE test_table (id int, value text)"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>tech.ydb.jdbc</groupId>

<artifactId>ydb-jdbc-driver-parent</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>

<name>YDB JDBC Module</name>
<description>JDBC Driver over YDB Java SDK</description>
Expand Down

0 comments on commit c10fdf0

Please sign in to comment.