Fork me on GitHub
#beginners
<
2022-01-07
>
Romit Gandhi07:01:09

Hello all, I'm using https://github.com/mpenet/alia as Apache Cassandra client in Clojure I want to run copy command (copy data from csv to table) but I'm getting an error.

(alia/execute @session (str "COPY " table " FROM '" file-name "' WITH DELIMITER=',' AND HEADER=TRUE;"))
I'm doing this but I'm getting an error that query qxecution failed but if I run same command in cqlsh then it is working perfectly. I also checked if file is exist or not using this
(println (.exists ( file-name)))
And it returns true. Getting this error #error { :cause line 1:0 no viable alternative at input 'COPY' ([COPY]...) :via [{:type clojure.lang.ExceptionInfo :message Query execution failed :data {:type :qbits.alia/execute, :query [:simple  COPY cities FROM 'resources/temp/0284e950-d479-47ed-8282-168e1fce563d.csv' WITH DELIMITER=',' AND HEADER=TRUE;], :statement #object[com.datastax.oss.driver.internal.core.cql.DefaultSimpleStatement 0x5a5e3a04 c[email protected]9135c8ac], :values nil} :at [qbits.alia.error$ex__GT_ex_info invokeStatic error.clj 50]} {:type com.datastax.oss.driver.api.core.servererrors.SyntaxError :message line 1:0 no viable alternative at input 'COPY' ([COPY]...) :at [com.datastax.oss.driver.api.core.servererrors.SyntaxError copy SyntaxError.java 48]}] :trace [[com.datastax.oss.driver.api.core.servererrors.SyntaxError copy SyntaxError.java 48] [com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures getUninterruptibly CompletableFutures.java 149] [com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor process CqlRequestSyncProcessor.java 53] [com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor process CqlRequestSyncProcessor.java 30] [com.datastax.oss.driver.internal.core.session.DefaultSession execute DefaultSession.java 230] [com.datastax.oss.driver.api.core.cql.SyncCqlSession execute SyncCqlSession.java 54] [qbits.alia$execute invokeStatic alia.clj 324] [qbits.alia$execute invoke alia.clj 251] [qbits.alia$execute invokeStatic alia.clj 332] [qbits.alia$execute invoke alia.clj 251] [back_end.db.core$bulk_insert_using_csv invokeStatic core.clj 22] [back_end.db.core$bulk_insert_using_csv invoke core.clj 18] [back_end.db.cassandra$insert_bulk_data_using_csv invokeStatic cassandra.clj 6] [back_end.db.cassandra$insert_bulk_data_using_csv invoke cassandra.clj 4] [back_end.handlers.cassandra$upload_csv_file invokeStatic cassandra.clj 36] [back_end.handlers.cassandra$upload_csv_file invoke cassandra.clj 27] [reitit.ring.middleware.multipart$compile$fn__12725$fn__12727$fn__12728 invoke multipart.clj 46] [muuntaja.middleware$wrap_format_request$fn__12621 invoke middleware.clj 114] [reitit.ring.coercion$fn__9455$fn__9457$fn__9458 invoke coercion.cljc 80] [muuntaja.middleware$wrap_format_response$fn__12625 invoke middleware.clj 132] [muuntaja.middleware$wrap_format_negotiate$fn__12618 invoke middleware.clj 96] [ring.middleware.params$wrap_params$fn__6862 invoke params.clj 67] [reitit.ring$ring_handler$fn__9120 invoke ring.cljc 329] [clojure.lang.AFn applyToHelper AFn.java 154] [clojure.lang.AFn applyTo AFn.java 144] [clojure.lang.AFunction$1 doInvoke AFunction.java 31] [clojure.lang.RestFn invoke RestFn.java 408] [clojure.lang.Var invoke Var.java 384] [ring.middleware.reload$wrap_reload$fn__5380 invoke reload.clj 39] [selmer.middleware$wrap_error_page$fn__5395 invoke middleware.clj 18] [prone.middleware$wrap_exceptions$fn__5637 invoke middleware.clj 169] [ring.middleware.flash$wrap_flash$fn__5680 invoke flash.clj 39] [ring.adapter.undertow.middleware.session$wrap_undertow_session$fn__6238 invoke session.clj 77] [ring.middleware.keyword_params$wrap_keyword_params$fn__6482 invoke keyword_params.clj 53] [ring.middleware.nested_params$wrap_nested_params$fn__6540 invoke nested_params.clj 89] [ring.middleware.multipart_params$wrap_multipart_params$fn__6838 invoke multipart_params.clj 171] [ring.middleware.params$wrap_params$fn__6862 invoke params.clj 67] [ring.middleware.cookies$wrap_cookies$fn__6011 invoke cookies.clj 214] [ring.middleware.absolute_redirects$wrap_absolute_redirects$fn__7050 invoke absolute_redirects.clj 47] [ring.middleware.resource$wrap_resource_prefer_resources$fn__6898 invoke resource.clj 25] [ring.middleware.content_type$wrap_content_type$fn__6998 invoke content_type.clj 34] [ring.middleware.default_charset$wrap_default_charset$fn__7022 invoke default_charset.clj 31] [ring.middleware.not_modified$wrap_not_modified$fn__6964 invoke not_modified.clj 61] [ring.middleware.x_headers$wrap_x_header$fn__6422 invoke x_headers.clj 22] [ring.middleware.x_headers$wrap_x_header$fn__6422 invoke x_headers.clj 22] [ring.middleware.x_headers$wrap_x_header$fn__6422 invoke x_headers.clj 22] [ring.adapter.undertow$undertow_handler$fn$reify__17593 handleRequest undertow.clj 40] [io.undertow.server.session.SessionAttachmentHandler handleRequest SessionAttachmentHandler.java 68] [io.undertow.server.Connectors executeRootHandler Connectors.java 387] [io.undertow.server.HttpServerExchange$1 run HttpServerExchange.java 852] [org.jboss.threads.ContextClassLoaderSavingRunnable run ContextClassLoaderSavingRunnable.java 35] [org.jboss.threads.EnhancedQueueExecutor safeRun EnhancedQueueExecutor.java 2019] [org.jboss.threads.EnhancedQueueExecutor$ThreadBody doRunTask EnhancedQueueExecutor.java 1558] [org.jboss.threads.EnhancedQueueExecutor$ThreadBody run EnhancedQueueExecutor.java 1449] [org.xnio.XnioWorker$WorkerThreadFactory$1$1 run XnioWorker.java 1280] [java.lang.Thread run Thread.java 829]]} So, please can anyone help me regarding this?

jumar09:01:45

I unfortunately know nothing about this but the first thing you should add is the error details like a stacktrace 🙂.

Romit Gandhi09:01:38

I have edited the message and pasted the stack trace

Antonio Bibiano12:01:19

Could be that this COPY command is specific to the util you used to test it? I remember that something similar used to happen with psql and postgresql

Antonio Bibiano12:01:31

Where you had this command to read a local csv and dump it into a table but you could not run a query to do the same thing using a driver

Antonio Bibiano12:01:53

looking at the docs that seems to be the case https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cqlsh_commands/cqlshCopyFrom.html COPY only appears under cqlsh commands

Daniel Craig16:01:09

you might need to escape the single quotes that are part of your query

emccue02:01:40

I think you might run into CQL injection if you write CQL like that

Romit Gandhi04:01:19

No there will not be cql injection as this is internal code and user will only able to upload CSV file and I'm not using same file name. I'm generating Uuid and save file as that name.

xbrln13:01:12

Hello all, am using https://github.com/seancorfield/next-jdbc to query from a postgres db. When I fetch a record from a table, in the result set, column name is represented as :table_name/column_name. Is there a way to get them as :column_name ?

xbrln15:01:53

Thank you. I added a map with :builder-fn and it works as I wanted.

dharrigan15:01:30

No problemo, you're most welcome 🙂

emccue02:01:58

while you are making that choice, try to think about if it makes sense to use the namespaced keys. I personally find them pretty powerful

SELECT a.name, b.name
FROM a
WHERE a.id = ?
INNER JOIN b ON b.a_id = a.id

emccue02:01:19

this would come out as {:a/name … :b/name …}

xbrln16:01:53

@U3JH98J4R This would have been my follow up question 🙂 Am used to working with namespace/keys and was wondering what are the benefits, or is it only a preference. The example you mentioned, with the join, I normally give a name to the tables in such cases and then I have something to identify the columns from each joined tables. So I do not find that example as an advantage for me 🙂 But are there any other benefits to use namespace/keys ?

dharrigan17:01:50

Yes, for example, the immediate benefit is if one has joins with similar column names in tables

dharrigan17:01:19

with namespaced keys, each key will be unique, i.e., :foo/id :bar/id

dharrigan17:01:35

That by itself, pays off so so much.

dharrigan17:01:29

I would suggest having a look here:

dharrigan17:01:49

and a few paragraphs down, i.e.,

dharrigan17:01:54

The unqualified options may be slightly faster than their qualified equivalents but make no attempt to keep column names unique if your SQL joins across multiple tables.

dharrigan17:01:47

I understand that you may alias each returned column, to keep the names unique, but that feels like more effort to maintain consistency.

xbrln19:01:10

Thanks again for the explanations @U11EL3P9U

dharrigan14:01:30

There's also #sql that is there for other sql related matters 🙂

👍 1
zendevil.eth16:01:16

I’m trying to start my server from the repl with (start) but getting:

user=> (start)
Execution error (ConnectException) at java.net.PlainSocketImpl/socketConnect (PlainSocketImpl.java:-2).
Connection refused (Connection refused)
What is happening?

zendevil.eth16:01:14

The port is 3000, and according to lsof -i:3000 there’s nothing running there

hiredman17:01:33

I would look at the rest of the stacktrace

hiredman17:01:53

my guess is something like connecting to a database is failing

zendevil.eth18:01:14

@hiredman There's no other stacktrace

hiredman18:01:09

what you shared is the print out of basically the start of a stacktrace

zendevil.eth18:01:26

This is the whole stacktrace

hiredman18:01:27

the exception object that was thrown will have the rest of it

hiredman18:01:46

your repl may not show the whole thing when it catches an error

hiredman18:01:11

but in the repl the latest exception thrown will be bound to *e

hiredman18:01:43

so typing *e in the repl should cause the exception object, including the entire stacktrace, to be printed

hiredman18:01:22

user=> (/ 1 0)
Execution error (ArithmeticException) at user/eval1 (REPL:1).
Divide by zero
user=> *e
#error {
 :cause "Divide by zero"
 :via
 [{:type java.lang.ArithmeticException
   :message "Divide by zero"
   :at [clojure.lang.Numbers divide "Numbers.java" 188]}]
 :trace
 [[clojure.lang.Numbers divide "Numbers.java" 188]
  [clojure.lang.Numbers divide "Numbers.java" 3901]
  [user$eval1 invokeStatic "NO_SOURCE_FILE" 1]
  [user$eval1 invoke "NO_SOURCE_FILE" 1]
  [clojure.lang.Compiler eval "Compiler.java" 7181]
  [clojure.lang.Compiler eval "Compiler.java" 7136]
  [clojure.core$eval invokeStatic "core.clj" 3202]
  [clojure.core$eval invoke "core.clj" 3198]
  [clojure.main$repl$read_eval_print__9112$fn__9115 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9112 invoke "main.clj" 437]
  [clojure.main$repl$fn__9121 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl_opt invokeStatic "main.clj" 522]
  [clojure.main$main invokeStatic "main.clj" 667]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn invoke "RestFn.java" 397]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.RestFn applyTo "RestFn.java" 132]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}
user=>

Alex Miller (Clojure team)18:01:34

pst = print stack trace and is designed for the purpose of a person reading a stack trace (not printing a data object)

👁️ 2
Alex Miller (Clojure team)18:01:30

*e will also only include the root cause stack, whereas pst includes stack of all exceptions in the chain

😯 1
ghadi19:01:21

a clojure atom?

ghadi19:01:59

you're actually running into some undefined behavior here

ghadi19:01:17

starts-with? needs to be passed a String or CharSequence

ghadi19:01:40

you happen to be passing an atom, which is not any of those

ghadi19:01:52

and it happens to be giving you an answer, but the answer is garbage

ghadi19:01:43

which is sugar for (deref atom)

ghadi19:01:40

atoms are reftypes / boxes. deref gets what's in the box

Muhammad Hamza Chippa20:01:25

I am using js/Date. to generate date from the object but it is not generating the date object in the desired timezone I want to generate the date in EST timezone "1818-08-12T05:06:00Z". Is there any method to generate the date object in the desired timezone I did not find such thing in the documentation ?

hiredman20:01:42

You are seeing how inst tagged literals print, and they always print normalized it utc, regardless of the time zone of the object

Muhammad Hamza Chippa20:01:35

I want to reatin the time 5:06 in gmt+2 timezone is there any way to do it ?

hiredman20:01:17

The way the object is printed doesn't effect the object