You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2021/05/21 07:40:45 UTC

[incubator-nlpcraft] branch master updated: Db related issues fixes.

This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f5a78d  Db related issues fixes.
3f5a78d is described below

commit 3f5a78d56447b6c07e380299f769dff6b04be76c
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Fri May 21 10:40:36 2021 +0300

    Db related issues fixes.
---
 nlpcraft/src/main/resources/sql/create_schema.sql       |  2 +-
 .../org/apache/nlpcraft/server/mdo/NCFeedbackMdo.scala  |  2 +-
 .../nlpcraft/server/mdo/impl/NCAnnotatedMdo.scala       | 17 +++++++++--------
 .../apache/nlpcraft/server/rest/NCBasicRestApi.scala    |  2 +-
 .../org/apache/nlpcraft/server/sql/NCSqlManager.scala   |  2 +-
 sql/mysql/schema.sql                                    |  4 ++--
 sql/oracle/schema.sql                                   |  7 ++++---
 sql/postgres/schema.sql                                 |  4 ++--
 8 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/nlpcraft/src/main/resources/sql/create_schema.sql b/nlpcraft/src/main/resources/sql/create_schema.sql
index 1965ca0..b652c51 100644
--- a/nlpcraft/src/main/resources/sql/create_schema.sql
+++ b/nlpcraft/src/main/resources/sql/create_schema.sql
@@ -111,7 +111,7 @@ CREATE TABLE feedback (
     srv_req_id VARCHAR NOT NULL,
     user_id LONG NOT NULL,
     score DOUBLE NOT NULL,
-    comment VARCHAR NULL,
+    feedback_comment VARCHAR NULL,
     created_on TIMESTAMP NOT NULL
 );
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/NCFeedbackMdo.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/NCFeedbackMdo.scala
index a2782de..d89f7da 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/NCFeedbackMdo.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/NCFeedbackMdo.scala
@@ -31,7 +31,7 @@ case class NCFeedbackMdo(
     @NCMdoField(column = "srv_req_id") srvReqId: String,
     @NCMdoField(column = "user_id") userId: Long,
     @NCMdoField(column = "score") score: Double,
-    @NCMdoField(column = "comment") comment: Option[String],
+    @NCMdoField(column = "feedback_comment") feedbackComment: Option[String],
     @NCMdoField(column = "created_on") createdOn: Timestamp
 ) extends NCAnnotatedMdo[NCFeedbackMdo]
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/impl/NCAnnotatedMdo.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/impl/NCAnnotatedMdo.scala
index 283a4ab..8e26fe1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/impl/NCAnnotatedMdo.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/mdo/impl/NCAnnotatedMdo.scala
@@ -188,16 +188,17 @@ object NCAnnotatedMdo {
             val (p, cls) = t
             val col = p.ann.column()
 
-            cls match {
-                // Special handling for options.
-                case x if x == classOf[Option[_]] ⇒
-                    val obj = rs.getObject(col)
+            // Special handling for options.
+            def getOption(rs: ResultSet, get: ResultSet ⇒ AnyRef): Option[AnyRef] = {
+                val obj = get(rs)
 
-                    if (rs.wasNull())
-                        None
-                    else
-                        Some(obj)
+                if (rs.wasNull()) None else Some(obj)
+            }
 
+            cls match {
+                // String processed special way because CLOB, TEXT etc nullable fields processing of different databases.
+                case x if x == classOf[Option[String]] ⇒ getOption(rs, rs ⇒ rs.getString(col))
+                case x if x == classOf[Option[_]] ⇒ getOption(rs, rs ⇒ rs.getObject(col))
                 // Handle AnyVals manually to get proper values in case of `NULL`s.
                 case x if x == classOf[Long] ⇒ rs.getLong(col)
                 case x if x == classOf[Int] ⇒ rs.getInt(col)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index 4d9750b..8690d41 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -1257,7 +1257,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
                             f.srvReqId,
                             f.userId,
                             f.score,
-                            f.comment,
+                            f.feedbackComment,
                             f.createdOn.getTime
                         )
                     )
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSqlManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSqlManager.scala
index 50ef05d..2914024 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSqlManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sql/NCSqlManager.scala
@@ -917,7 +917,7 @@ object NCSqlManager extends NCService with NCIgniteInstance {
     def addFeedback(id: Long, srvReqId: String, userId: Long, score: Double, comment: Option[String], parent: Span): Long = {
         startScopedSpan("addFeedback", parent, "srvReqId" → srvReqId, "userId" → userId) { _ ⇒
             NCSql.insert(
-                "INSERT INTO feedback(id, srv_req_id, user_id, score, comment, created_on) VALUES(?, ?, ?, ?, ?, ?)",
+                "INSERT INTO feedback(id, srv_req_id, user_id, score, feedback_comment, created_on) VALUES(?, ?, ?, ?, ?, ?)",
                 id, srvReqId, userId, score, comment.orNull, U.nowUtcTs()
             )
 
diff --git a/sql/mysql/schema.sql b/sql/mysql/schema.sql
index 9022ab6..9f208e6 100644
--- a/sql/mysql/schema.sql
+++ b/sql/mysql/schema.sql
@@ -98,7 +98,7 @@ CREATE TABLE proc_log (
     -- Result parts.
     res_type VARCHAR(32) NULL,
     res_body_gzip TEXT NULL, -- GZIP-ed result body.
-    res_body_meta TEXT NULL, -- GZIP-ed result meta.
+    res_meta_gzip TEXT NULL, -- GZIP-ed result meta.
     intent_id VARCHAR(256) NULL,
     error TEXT NULL,
     -- Probe information for this request.
@@ -132,7 +132,7 @@ CREATE TABLE feedback (
     srv_req_id VARCHAR(64) NOT NULL,
     user_id BIGINT NOT NULL,
     score DECIMAL NOT NULL,
-    comment VARCHAR(1024) NULL,
+    feedback_comment VARCHAR(1024) NULL,
     created_on TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(3)
 );
 
diff --git a/sql/oracle/schema.sql b/sql/oracle/schema.sql
index da243b9..577c11f 100644
--- a/sql/oracle/schema.sql
+++ b/sql/oracle/schema.sql
@@ -66,7 +66,8 @@ CREATE TABLE nc_user (
 );
 
 CREATE UNIQUE INDEX nc_user_idx_1 ON nc_user(email);
-CREATE UNIQUE INDEX nc_user_idx_2 ON nc_user(company_id, ext_id);
+-- Drop it if your Oracle version doesn't support this syntax.
+CREATE UNIQUE INDEX nc_user_idx_2 ON nc_user(CASE WHEN ext_id IS NOT NULL THEN company_id END, CASE WHEN ext_id IS NOT NULL THEN ext_id END);
 CREATE INDEX nc_user_idx_3 ON nc_user(company_id);
 
 --
@@ -97,7 +98,7 @@ CREATE TABLE proc_log (
     -- Result parts.
     res_type VARCHAR2(32) NULL,
     res_body_gzip CLOB NULL, -- GZIP-ed result body.
-    res_body_meta CLOB NULL, -- GZIP-ed result meta.
+    res_meta_gzip CLOB NULL, -- GZIP-ed result meta.
     intent_id VARCHAR2(256) NULL,
     error CLOB NULL,
     -- Probe information for this request.
@@ -131,7 +132,7 @@ CREATE TABLE feedback (
     srv_req_id VARCHAR2(64) NOT NULL,
     user_id NUMBER NOT NULL,
     score NUMBER NOT NULL,
-    comment VARCHAR2(1024) NULL,
+    feedback_comment VARCHAR2(1024) NULL,
     created_on DATE DEFAULT sysdate NOT NULL
 );
 
diff --git a/sql/postgres/schema.sql b/sql/postgres/schema.sql
index 8329ed7..4edf3e2 100644
--- a/sql/postgres/schema.sql
+++ b/sql/postgres/schema.sql
@@ -98,7 +98,7 @@ CREATE TABLE proc_log (
     -- Result parts.
     res_type VARCHAR(32) NULL,
     res_body_gzip TEXT NULL, -- GZIP-ed result body.
-    res_body_meta TEXT NULL, -- GZIP-ed result body.
+    res_meta_gzip TEXT NULL, -- GZIP-ed result body.
     intent_id VARCHAR(256) NULL,
     error TEXT NULL,
     -- Probe information for this request.
@@ -132,7 +132,7 @@ CREATE TABLE feedback (
     srv_req_id VARCHAR(64) NOT NULL,
     user_id BIGINT NOT NULL,
     score NUMERIC NOT NULL,
-    comment VARCHAR(1024) NULL,
+    feedback_comment VARCHAR(1024) NULL,
     created_on TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(3)
 );