Comments (12)
Array(Uint32) like [0,12191] is ok
but Array(String) like ['071','122'] is not ok
from clickhouse4j.
type: Array(UInt32), parsed text: "[0,12191]"
name: event_id, type: Array(String), parsed text: <EMPTY>ERROR
from clickhouse4j.
@Tasselmi could you please provide minimal sql statement example?
from clickhouse4j.
@Tasselmi could you please provide minimal sql statement example?
I use spark's default df.write.format("jdbc")
method.
now I'm trying to maintain a connection pool by myself.
If also does not work, I will give more details.
Thanks
from clickhouse4j.
@Tasselmi ok. I'll try to reproduce by myself for now.
from clickhouse4j.
@Tasselmi pushed additional test - it works just fine. We need more info. Minimal reproducer would be nice.
from clickhouse4j.
@Tasselmi pushed additional test - it works just fine. We need more info. Minimal reproducer would be nice.
CREATE TABLE test.test
(
`age` UInt8,
`name` Array(String)
)
ENGINE = Log
$ spark-shell --num-executors 1 --executor-memory 4g --executor-cores 1 --jars /home/me/jars/clickhouse4j-1.1.1.jar
scala> :paste
// Entering paste mode (ctrl-D to finish)
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
import org.apache.spark.sql.{Row, SaveMode, SparkSession}
import org.apache.spark.storage.StorageLevel
// Exiting paste mode, now interpreting.
scala> val df = Seq((18, "liang"), (18, "fan")).toDF("age", "name")
df: org.apache.spark.sql.DataFrame = [age: int, name: string]
scala> df.show
+---+-----+
|age| name|
+---+-----+
| 18|liang|
| 18| fan|
+---+-----+
scala> val dfa = df.groupBy("age").agg(collect_list("name").as("name_list"))
dfa: org.apache.spark.sql.DataFrame = [age: int, name_list: array<string>]
scala> dfa.show
+---+------------+
|age| name_list|
+---+------------+
| 18|[liang, fan]|
+---+------------+
scala> :paste
// Entering paste mode (ctrl-D to finish)
val rdd = dfa.rdd.map { row =>
val age = row.getAs[Int]("age")
val name = row.getAs[Seq[String]]("name_list")
Row(age, name.map(e => "\'" + e + "\'").mkString("[", ",", "]"))
}
val schema = StructType(
Seq(
StructField("age", IntegerType),
StructField("name", StringType)
)
)
val dfb = spark.createDataFrame(rdd, schema)
dfb.show()
// Exiting paste mode, now interpreting.
+---+---------------+
|age| name|
+---+---------------+
| 18|['liang','fan']|
+---+---------------+
scala> :paste
dfb.write
.mode(SaveMode.Append)
.format("jdbc")
.option("url", dburl)
.option("driver", driverClass4j)
.option("dbtable", "test")
.option("user", userMe)
.option("password", passwordMe)
.save()
ClickHouse exception, code: 26, host: null, port: 0; Code: 26, e.displayText() = DB::Exception: Cannot parse quoted string: expected opening quote: (at row 1)
Row 1:
Column 0, name: age, type: UInt8, parsed text: "18"
Column 1, name: name, type: Array(String), parsed text: <EMPTY>ERROR
(version 19.16.2.2 (official build))
but just look at the printing:
+---+---------------+
|age| name|
+---+---------------+
| 18|['liang','fan']|
+---+---------------+
the format is right....
from clickhouse4j.
I use connectionPool to insert, and the error is the same.
This makes me puzzled a whole day.
looking forward your help.
from clickhouse4j.
@Tasselmi any way to view the generated sql?
from clickhouse4j.
@Tasselmi any way to view the generated sql?
ok let me figure out.
from clickhouse4j.
@Tasselmi any way to view the generated sql?
sorry I can not to get the generated sql.
But here are some clues.
money
and name
are string type in spark.
money
is Array(Int)
and name
is Array(String)
in clickhouse.
money
works fine, but name
fails.
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
import org.apache.spark.sql.{Row, SaveMode, SparkSession}
import org.apache.spark.storage.StorageLevel
val dburl = "jdbc:clickhouse://localhost:8123/test"
val driverClass4j = "cc.blynk.clickhouse.ClickHouseDriver"
val df = Seq((18, 1000, "liang"), (18, 2000, "fan")).toDF("age", "money", "name")
val dfa = df.groupBy("age").agg(
collect_list("money").as("money_list"),
collect_list("name").as("name_list")
)
val rdd = dfa.rdd.map { row =>
val age = row.getAs[Int]("age")
val money = row.getAs[Seq[Int]]("money_list")
val name = row.getAs[Seq[String]]("name_list")
Row(age,
money.mkString("[", ",", "]"),
name.map(e => "\'" + e + "\'").mkString("[", ",", "]")
)
}
val schema = StructType(
Seq(
StructField("age", IntegerType),
StructField("money", StringType),
StructField("name", StringType)
)
)
val dfb = spark.createDataFrame(rdd, schema)
scala> dfb.show
+---+-----------+-------------+
|age| money| name|
+---+-----------+-------------+
| 18|[1000,2000]|'liang','fan'|
+---+-----------+-------------+
dfb.write
.mode(SaveMode.Append)
.format("jdbc")
.option("url", dburl)
.option("driver", driverClass4j)
.option("dbtable", "test")
.option("user", "default")
.option("password", "")
.save()
Caused by: java.lang.Throwable: Code: 27, e.displayText() = DB::Exception: Cannot parse input: expected [ before: \\\'liang\\\',\\\'fan\\\'\n: (at row 1)
Row 1:
Column 0, name: age, type: UInt8, parsed text: "18"
Column 1, name: money, type: Array(UInt16), parsed text: "[1000,2000]"
Column 2, name: name, type: Array(String), parsed text: <EMPTY>ERROR
(version 19.16.2.2 (official build))
at cc.blynk.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:56)
... 21 more
scala> dfb.show
+---+-----------+---------------+
|age| money| name|
+---+-----------+---------------+
| 18|[1000,2000]|['liang','fan']|
+---+-----------+---------------+
dfb.write
.mode(SaveMode.Append)
.format("jdbc")
.option("url", dburl)
.option("driver", driverClass4j)
.option("dbtable", "test")
.option("user", "default")
.option("password", "")
.save()
Caused by: java.lang.Throwable: Code: 26, e.displayText() = DB::Exception: Cannot parse quoted string: expected opening quote: (at row 1)
Row 1:
Column 0, name: age, type: UInt8, parsed text: "18"
Column 1, name: money, type: Array(UInt16), parsed text: "[1000,2000]"
Column 2, name: name, type: Array(String), parsed text: <EMPTY>ERROR
and if I make some mistakes in purpose, I find that format above is right. I put double quote on each side, and the content parsed are right :
scala> dfb.show
+---+-----------+-----------------+
|age| money| name|
+---+-----------+-----------------+
| 18|[1000,2000]|"['liang','fan']"|
+---+-----------+-----------------+
Caused by: java.lang.Throwable: Code: 27, e.displayText() = DB::Exception: Cannot parse input: expected [ before: "[\\\'liang\\\',\\\'fan\\\']"\n: (at row 1)
Row 1:
Column 0, name: age, type: UInt8, parsed text: "18"
Column 1, name: money, type: Array(UInt16), parsed text: "[1000,2000]"
Column 2, name: name, type: Array(String), parsed text: <EMPTY>ERROR
so i do not know why
from clickhouse4j.
@Tasselmi hello, have you found the root cause? I'm closing cause it seems it is not driver issue. Feel free to reopen if you think this is a driver issue.
from clickhouse4j.
Related Issues (20)
- SpringBoot 3.0.1: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
- Is project still active? HOT 1
- unable to catch any exception that occurs during copyFromDB call HOT 1
- Lz4 should use the fastest instance (current safe instance is used)
- Remove param descriptions to minimize driver size.
- Client service uses all ports HOT 12
- Provide non-default plugable HTTP Clients
- Remove ExternalData support HOT 6
- Unable to connect to clickhouse through HAProxy HOT 7
- Provide a better method for setting the arrays
- Empty Authorization header is submitted if no auth is defined HOT 2
- Password with special characters not properly URL encoded HOT 1
- Is CopyManager thread safe ? HOT 1
- Error when insert `Array(String)` in Spark
- socket_timeout not working
- Merge changes back to official JDBC driver HOT 2
- how can i implements batch delete? HOT 1
- Improve JAR packaging (re-packaged net.jpountz.lz4)
- Server log filled with errors HOT 2
- ConnectionTimeout This property cannot be set and will be overridden by the default value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clickhouse4j.