Sqoop import not working with hive parquet - import

Change data capture in Sqoop-Hive Import
I am trying to do change data capture using Sqoop but when I am writing -as-parquet I my Sqoop import command it is falling .but after removing -as-parquet from my Sqoop command it is working and putting data in text format in hive table but want it in parquet hive table.
i want to do update operation from my data.

I have written this below command :
Sqoop import --connect "myoracleconntiondetails"
--username myuser --password mypasswd
--query 'select * from test_table where $CONDITIONS'
--hive_import --hive-database test_dase
--hive-table test_dase.test_table --null-string 'NULL'
--null-non-string '-99999' --target-dir mydir/full path
--split-by mycol --incremental append
--merge-key could -as-parquet -m -10
I get this error:
Got exception running sqoop: org.kitesdk.data.validationException: Dataset name test_dase.test_table is not alphanumeric (plus '')
Org.kitesdk.data.validation:Dataset name test_dase.test_table is not alphanumeric (plus '')

Related

sqoop query is giving error for the Import command

I am trying to transfer 35 GB table from aws rds postgres to hive but when I try to full table it take much time and after long time execution get stop. so I decide to load incremental way.
schema:All are in varchar except mentioned below.
twoway_id
twoway_seq =>int
guid
twoway_section_cd
transmit_host_nm
receipt_host_nm
service_id
msg_id
msg_no
vin_id
twoway_dt
status_result_cd
company_cd
limit_count_yn
response_status_cd
create_user_id
create_app_id
create_tmsmp =>timestamp
update_user_id
update_app_id
update_tmsmp =>timestamp
kshsjsjsj 320393682 IN K 02 TMU ISS CMM GPI 14 0 20201800230936 FAIL 02 Y 500 ISS ISS 2020-12-02 17:36:36.447 ISS ISS 2020-12-02 17:36:36.462
326403236
sqoop query: This query is working perfectly for full table load.
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k"\
--query 'SELECT * FROM db_core.service_twoway_ifo_202012 where 1=1 AND $CONDITIONS'\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--hive-import --hive-table db_core.service_twoway_ifo_202012\
--hive-drop-import-delims\
--hive-overwrite --hs2-url jdbc:hive2://hivehostname:10000/default;
tried but not working
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k"\
--query 'SELECT * FROM db_core.service_twoway_ifo_202012 where create_tmsmp like '2020-12-01%' AND $CONDITIONS'\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--hive-import --hive-table db_core.service_twoway_ifo_202012\
--hive-drop-import-delims\
--hive-overwrite --hs2-url jdbc:hive2://hivehostname:10000/default;
Error:
21/12/29 16:02:43 ERROR manager.SqlManager: Error executing statement: org.postgresql.util.PSQLException:
ERROR: operator does not exist: integer % boolean
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
This is also not working
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k \
--table `db_core.service_twoway_ifo_202112`\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--where "create_tmsmp < 2020-12-04 04:51:26.150"\
--append
Also help me on incremental load query. I am also facing syntax error issue.
Incremental import arguments:
Argument Description
--check-column (col) Specifies the column to be examined when determining which rows to import.
--incremental (mode) Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified.
--last-value (value) Specifies the maximum value of the check column from the previous import.
I think the way you are passing --where need to be changed like below. You need to use single quotes around strings.
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k \
--table `db_core.service_twoway_ifo_202112`\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--where " create_tmsmp < TO_TIMESTAMP('2020-12-04 04:51:26','YYYY-MM-DD HH:MI:SS' )"\
or
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k"\
--query "SELECT * FROM db_core.service_twoway_ifo_202012 where create_tmsmp < TO_TIMESTAMP('2020-12-04 04:51:26','YYYY-MM-DD HH:MI:SS') AND \\\$CONDITIONS"\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--hive-import --hive-table db_core.service_twoway_ifo_202012\
Pls change position of \$CONDITIONS if above doesn't work.
Now you can implement Incremental sqoop like below.
NEW ROWS : you can use --incremental append to append new records. identify a column which can be used to determine brand new record - like primary key. And also calculate max() of that column in hive(i assumed it to be 1000). Load those data using below sqoop.
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k \
--table `db_core.service_twoway_ifo_202112`\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--check-column pk_col \
--incremental append \
--last-value 1000
So this above Sqoop will append any row where pk_col > 10000 from postgres.
EXISTING ROWS : Similarly you may want to bring modified rows from source. Then use below SQL. You need to first calculate max() of create_tmsmp and then use it in below statement(i assumed max to be 2020-12-04 04:51:26).
sqoop import --connect "jdbc:postgresql://hostname:5432/db_core_k \
--table `db_core.service_twoway_ifo_202112`\
--m 1 --target-dir "/user/hive/warehouse/db_core.db/service_twoway_ifo_202112"\
--username test --password test001 \
--check-column create_tmsmp \
--incremental lastmodified \
--last-value "'2020-12-04 04:51:26'"

sqoop import create hive table, the table not found in the specified database

I write the following sqoop command :
sqoop import --connect jdbc:mysql://localhost/export --username root --password cloudera --table cust --create-hive-table --fields-terminated-by ' ' --hive-table default.cust -m 1
Then, I could not found the table in default database but the file appeared in /user/cloudera/cust
Use —hive-import and -hive-overwrite if it is a overwrite table. You can also mention the —target-dir

Sqoop - Use schema in saved job

When I run this command on shell works fine:
sqoop import --incremental append --check-column id_civilstatus --last-value -1
--connect jdbc:postgresql://somehost/somedb --username someuser
--password-file file:///passfile.txt --table sometable --direct -m 3
--target-dir /jobs/somedir -- --schema someschema
But when I try to save it as a job:
sqoop job --create myjob -- import --incremental append --check-column id_civilstatus
--last-value -1 --connect jdbc:postgresql://somehost/somedb --username someuser
--password-file file:///passfile.txt --table sometable --direct -m 3
--target-dir /jobs/somedir -- --schema someschema
Then I execute:
sqoop job --exec myjob
I get this error message:
PSQLException: ERROR: relation "sometable" does not exist
This is error due to 'sometable' does not exists in default schema.
Why sqoop job soes not take schema parameter? I am missing something?
Thanks
You can specify /change default schema passing "?currentSchema=myschema"in jdbc connection More detail .
jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema
You don’t need to mention schema separately, you can either keep it in jdbc URL, not sure if postgres jdbc URL have that option or not. You have to add it in the table option itself. Something like below
—table schemaName.tableName
Use the following as your JDBC URL
jdbc:postgresql://somehost/somedb/someschema
and remove --schema someschema from the Sqoop Statement.
I found a way to make this work here.
sqoop job --exec myjob -- -- --schema someschema

Mongo Import - Failed: fields '' and '.' are incompatible

I'm importing external data from Oracle to HDFS using Sqoop, after that I'm trying to import it to MongDB, follow the command that I'm usign and the error message:
-- Import external file to HDFS
sqoop import \
--connect "jdbc:oracle:thin:#(description=(address=(protocol=tcp)(host=hostname)(port=1521))(connect_data=(service_name=SID)))" \
--username user --table schema. my_table \
--num-mappers 1 --verbose -P
--Import HDFS file to MongoDB
hadoop fs -text /user/cloudera/mytable/part* | mongoimport -d database -c my_table --type csv --headerline
Error:
mongoimport: /usr/lib64/libcrypto.so.10: no version information
available (required by mongoimport) mongoimport:
/usr/lib64/libssl.so.10: no version information available (required by
mongoimport) 2015-12-08T07:08:24.001-0800 Failed: fields '' and '.'
are incompatible 2015-12-08T07:08:24.001-0800 imported 0 documents
text: Unable to write to output stream.

Importing postgresql arrays to hive

I've been using Sqoop to move data between Postgresql tables and Hive. But apparently Sqoop does not support the Postgresql array type.
Postgresql has a function called array_to_string. You can utilize that to transform your array to a string.
To illustrate, here is the table in postgresql:
=# select * from albums;
id | album_id | names
-----------+-------+-----
123 | {1,2,3,4} | test
(1 row)
=#
As you see the album_id has array as type, more specifically an array of integers.
Now, to import this from my database called mydb I use the following command:
sqoop import --connect jdbc:postgresql://localhost:5432/mydb \
--query "select id, array_to_string(album_id,',','*'), names \
from albums where \$CONDITIONS" \
--split-by id \
--target-dir albums
After that you can create create an external Hive table with the following parameters:
collection.delim $
field.delim ,