You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "nizhikov (via GitHub)" <gi...@apache.org> on 2024/09/04 08:12:35 UTC

Re: [PR] IGNITE-6141 JDBC: add basic support for BLOB and CLOB types [ignite]

nizhikov commented on code in PR #11492:
URL: https://github.com/apache/ignite/pull/11492#discussion_r1743126965


##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java:
##########
@@ -1090,14 +1091,14 @@ private List<? extends FieldsQueryCursor<List<?>>> executeDml(
             if (roEx != null) {
                 throw new IgniteSQLException(
                     "Failed to execute DML statement. Cluster in read-only mode [stmt=" + qryDesc.sql() +
-                    ", params=" + Arrays.deepToString(qryParams.arguments()) + "]",
+                    ", params=" + S.toString(QueryParameters.class, qryParams) + "]",
                     IgniteQueryErrorCode.CLUSTER_READ_ONLY_MODE_ENABLED,
                     e
                 );
             }
 
             throw new IgniteSQLException("Failed to execute DML statement [stmt=" + qryDesc.sql() +
-                ", params=" + Arrays.deepToString(qryParams.arguments()) + "]", e);
+                    ", params=" + S.toString(QueryParameters.class, qryParams) + "]", e);

Review Comment:
   Why this change?



##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcClob.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * CLOB implementation for Ignite JDBC driver.
+ */
+public class JdbcClob implements Clob {
+    /** CLOB's character sequence. */
+    private String chars;
+
+    /**
+     * @param chars CLOB's character sequence.
+     */
+    public JdbcClob(String chars) {
+        this.chars = chars;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long length() throws SQLException {
+        ensureNotClosed();
+
+        return chars.length();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSubString(long pos, int len) throws SQLException {
+        ensureNotClosed();
+
+        if (pos < 1 || len < 0 || pos - 1 + len > chars.length())

Review Comment:
   Can we cast `pos` to standard value as a first step to overcome API inconsistency and make code more readable:
   
   ```
   pos = pos - 1;
   
          if (pos < 0 || len < 0 || pos + len > chars.length())
               throw new SQLException("Invalid argument. Position should be greater than 0. Length should not be " +
                   "negative. Position + length should be less than CLOB size [pos=" + (pos+1) + ", length=" + len + ']');
   
           return chars.substring((int)pos, (int)pos + len);
   ```



##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java:
##########
@@ -1090,14 +1091,14 @@ private List<? extends FieldsQueryCursor<List<?>>> executeDml(
             if (roEx != null) {
                 throw new IgniteSQLException(
                     "Failed to execute DML statement. Cluster in read-only mode [stmt=" + qryDesc.sql() +
-                    ", params=" + Arrays.deepToString(qryParams.arguments()) + "]",
+                    ", params=" + S.toString(QueryParameters.class, qryParams) + "]",

Review Comment:
   Why this change?



##########
modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcClobTest.java:
##########
@@ -0,0 +1,744 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for JDBC CLOB.
+ */
+public class JdbcClobTest {
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testLength() throws Exception {
+        JdbcClob clob = new JdbcClob("1234567890");
+
+        assertEquals(10, clob.length());
+
+        clob.free();
+
+        try {

Review Comment:
   Can we use assertThrows here and below?



##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcBlob.java:
##########
@@ -54,7 +54,7 @@ public JdbcBlob(byte[] arr) {
     @Override public byte[] getBytes(long pos, int len) throws SQLException {
         ensureNotClosed();
 
-        if (pos < 1 || arr.length - pos < 0 || len < 0)
+        if (pos < 1 || (arr.length - pos < 0 && arr.length > 0) || len < 0)

Review Comment:
   Can you, please, clarify - why do we need new clause `arr.length > 0`?



##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParameters.java:
##########
@@ -20,13 +20,16 @@
 
 import java.util.List;
 import org.apache.ignite.internal.processors.query.NestedTxMode;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
 
 /**
  * Query parameters which vary between requests having the same execution plan. Essentially, these are the arguments
  * of original {@link org.apache.ignite.cache.query.SqlFieldsQuery} which are not part of {@link QueryDescriptor}.
  */
 public class QueryParameters {
     /** Arguments. */
+    @GridToStringInclude(sensitive = true)

Review Comment:
   Is this only field that will be printed out?
   Don't we need other fields?



##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcClob.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * CLOB implementation for Ignite JDBC driver.
+ */
+public class JdbcClob implements Clob {

Review Comment:
   Can we migrate to the `char[]` based implementation?
   It's not clear from the API, but looks like `Reader getCharacterStream()` or `getAsciiStream()` expects to see changes in underlying object if they happens after `getCharacterStream()` invocation.



##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcClob.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.jdbc2;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * CLOB implementation for Ignite JDBC driver.
+ */
+public class JdbcClob implements Clob {

Review Comment:
   Let's fix all `pos` argument somehow to make value 0 based and consistent with String and any other API.
   For example, make copy of all methods with `pos`, like:
   
   ```
   public String getSubString(int pos, int len) {
       return getSubStringInternal(pos - 1, len);
   }
   
   private getSubstringInternal(int pos, int len) {
       // 0 index based implementation.
   }
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org