Aerospike aql Syntax error near token - Make sure string values are enclosed in quotes - aerospike

I'm trying to delete the records from aeropike datastore set.
I'm using the query language given here.
But looks like the query has syntax error.I've given below the query and respective error.
Aerospike Query Client
Version 3.13.0.1
C Client Version 4.1.6
Copyright 2012-2016 Aerospike. All rights reserved.
aql> set TIMEOUT 100000
aql> delete from test.User
Syntax error near token - 'delete from test.User'
Make sure string values are enclosed in quotes.
Type " aql --help " from console or simply "help" from within the aql-prompt.
aql> delete from 'test.User'
Syntax error near token - 'delete from 'test.User''
Make sure string values are enclosed in quotes.
Type " aql --help " from console or simply "help" from within the aql-prompt.
aql> truncate test.User
ERROR: 404: COMMAND NOT FOUND : truncate
aql> truncate test User
ERROR: 404: COMMAND NOT FOUND : truncate
aql> truncate ns
ERROR: 404: COMMAND NOT FOUND : truncate
aql> select '_id' from test.User
+-----------+
| _id |
+-----------+
| "Dave-02" |
| "Dave-01" |
+-----------+
2 rows in set (1.413 secs)
aql> delete from test.User where '_id'="Dave-01"
Unsupported command format with token - ''_id''
Make sure string values are enclosed in quotes.
Type " aql --help " from console or simply "help" from within the aql-prompt.
aql> show namespaces
+------------+
| namespaces |
+------------+
| "test" |
| "bar" |
+------------+
2 rows in set (0.001 secs)
OK
aql> show sets
+------------------+--------+----------------+---------+-------------------+--------------+-------------------+--------------+------------+
| disable-eviction | ns | set-enable-xdr | objects | stop-writes-count | set | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+--------------+-------------------+--------------+------------+
| "false" | "test" | "use-default" | 0 | 0 | "UserRecord" | 0 | 0 | 0 |
| "false" | "bar" | "use-default" | 1 | 0 | "UserRecord" | 1230 | 0 | 0 |
+------------------+--------+----------------+---------+-------------------+--------------+-------------------+--------------+------------+
2 rows in set (0.000 secs)
OK
Any idea what is wrong in my query.
Thanks in advance.

aql> insert into ns1.user (pk, name, age) values (1, 'Raj', 24)
OK, 1 record affected.
aql> insert into ns1.user (pk, name, age) values (2, 'Kumar', 24)
OK, 1 record affected.
aql> select * from ns1.user
+---------+-----+
| name | age |
+---------+-----+
| "Raj" | 24 |
| "Kumar" | 24 |
+---------+-----+
2 rows in set (0.039 secs)
OK
aql> delete from ns1.user where pk = 1
OK, 1 record affected.
aql> select * from ns1.user
+---------+-----+
| name | age |
+---------+-----+
| "Kumar" | 24 |
+---------+-----+
1 row in set (0.038 secs)
OK
Extending the example further (also showing with key_send set to true) for ease of understanding, showing how truncate works.
aql> set key_send true
KEY_SEND = true
aql> insert into ns1.user (pk, name, age) values (1, 'Raj', 24)
OK, 1 record affected.
aql> insert into ns1.user (pk, name, age) values (2, 'Kumar', 25)
OK, 1 record affected.
aql> select * from ns1.user
+----+---------+-----+
| PK | name | age |
+----+---------+-----+
| 1 | "Raj" | 24 |
| 2 | "Kumar" | 25 |
+----+---------+-----+
2 rows in set (0.037 secs)
OK
aql> truncate ns1.user
OK
aql> select * from ns1.user
0 rows in set (0.036 secs)
OK

Related

How to query the metadata(such as ttl) of record from aql?

Assume you have a set as follows:
+-------+-------+
| PK | value |
+-------+-------+
| "pk1" | 24 |
+-------+-------+
1 row in set (0.105 secs)
How to get the metadata for this?
To get the metadata, all you need to do is run this command before running the query:
set RECORD_PRINT_METADATA true
Now, when you query the set
select * from test.segments
you can see additional metadata of the set, as follows:
+-------+-------+--------------------------------+------------+-------+-------+
| PK | value | {edigest} | {set} | {ttl} | {gen} |
+-------+-------+--------------------------------+------------+-------+-------+
| "pk1" | 24 | "Rn/5rHEQGWvPOSBK+vHRMyLkFyo=" | "segments" | 57 | 1 |
+-------+-------+--------------------------------+------------+-------+-------+
1 row in set (0.175 secs)
NOTE:
The command has to be run just once. It holds true for all the queries that come after it.
To go back to the default behaviour, set the argument to false

Impala sub-query returns strange result

I am running the below impala query and i am getting strange results. Why does the 2th query below returns zero results and how to overcome this. I am doing several data pipelines with multiple tables, so i have to use the "with" in the beginning.
1. Query: select * from test where name <> 'INSERT'
+----+--------+
| id | name |
+----+--------+
| 2 | DELETE |
| 2 | HELLO |
+----+--------+
Fetched 2 row(s) in 0.13s
2. Query: with temp as (select * from test where name <> 'INSERT') select * from temp
Modified 0 row(s) in 0.23s
3. Query: with temp as (select * from test where name <> 'HELLO') select * from temp
+----+--------+
| id | name |
+----+--------+
| 2 | DELETE |
| 1 | INSERT |
+----+--------+
Fetched 2 row(s) in 0.12s
It should give the record names with 'HELLO' and 'DELETE' for the 2nd query. but its giving no results. Also noticed the output says "modified", so i am guessing its trying to execute it as DML.
Note : Using Impala Shell v2.11.0-cdh5.14.2
The same query works fine in hive.
It seems to work on my side
with temp as (SELECT *
FROM
(SELECT 'DELETE' AS name
UNION SELECT 'HELLO' AS name
UNION SELECT 'INSERT' AS name) AS subq
WHERE name <> 'INSERT')
select * from temp;
+---------+
| name |
+---------+
| HELLO |
| DELETE |
+---------+
2 rows selected (0.118 seconds)
Could you post the EXPLAIN PLAN of your second query?

Stored Procedures - Updating and Inserting

I'm new to using stored procedures, what is the best way to update and insert using stored procedures. I have two tables and I can match them by a distinct ID, I want to update if the ID exists in both my load table and my destination table, and I want to insert if the item does not exist in my destination table. Just an example template would be very helpful, thanks!
If I understood well, you want to select values in one table and insert them in other table. If the id exists in the second table, you need to update the row. If I'm not wrong you need something like this:
mysql> select * from table_1;
+----+-----------+-----------+
| id | name | last_name |
+----+-----------+-----------+
| 1 | fagace | acero |
| 2 | ratangelo | saleh |
| 3 | hectorino | josefino |
+----+-----------+-----------+
3 rows in set (0.00 sec)
mysql> select * from table_2;
+----+-----------+-----------+
| id | name | last_name |
+----+-----------+-----------+
| 1 | fagace | acero |
| 2 | ratangelo | saleh |
+----+-----------+-----------+
2 rows in set (0.00 sec)
mysql> insert into table_2 select t1.id,t1.name,t1.last_name from table_1 t1 on duplicate key update name=t1.name, last_name=t1.last_name;
Query OK, 1 row affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from table_2;
+----+-----------+-----------+
| id | name | last_name |
+----+-----------+-----------+
| 1 | fagace | acero |
| 2 | ratangelo | saleh |
| 3 | hectorino | josefino |
+----+-----------+-----------+
3 rows in set (0.00 sec)
mysql>
You should look up the SQL MERGE statement.
It allows you to perform UPSERT's - i.e. INSERT if a key value does not already exist, UPDATE if the key does exist.
http://technet.microsoft.com/en-us/library/bb510625.aspx
However, your requirement to check for a key value in 2 places before you perform an update does make it more complex. I haven't tried this but I would think a VIEW or a CTE could be used to establish if the ID exists in both your tables & then base the MERGE on the CTE/VIEW.
But definitely start by looking at MERGE!

Google Cloud SQL - "SELECT .. AS .." doesn't change the column name

I'm trying to retrieve some columns value from a google cloud sql database, and I want to rename the output column as follows:
select id as tot from mytable
the query result I get is this:
id
value1
value2
value3
...
as you can see the column name is not changed as I wanted.. I also tried
select id as 'tot' from mytable
and (in fact this works, but obviously every row value is set to 'id' instead of the real row value)
select 'id' as 'tot' from mytable
the table schema I'm testing on is as simple as possible:
create table mytable(id varchar(10))
Has anyone encountered this problem before? Am I missing something or doing something wrong?
Thanks in advance for any help, best regards
This works as expected using the command line tool and looks like a bug in the web ui.
Here's what I got from the command line tool use (google_sql.sh)
sql> insert into mytable values('1'), ('2'), ('3');
3 row(s) affected.
sql> select * from mytable;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
+----+
3 rows in set (0.10 sec)
sql> select id as 'tot' from mytable
-> ;
+-----+
| tot |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
3 rows in set (0.09 sec)
sql> select 'id' as 'tot' from mytable
-> ;
+-----+
| tot |
+-----+
| id |
| id |
| id |
+-----+
3 rows in set (0.09 sec)
I just logged a bug for this: https://code.google.com/p/googlecloudsql/issues/detail?id=60

Raw copy of database leads to `Can't find file:`

To migrate my database faster, I tried copying the raw files (MYD and MYI) files of a database into another machine. All the tables are working fine except two tables that were partitioned. My directory structure looks like this:
table1.frm
table1.MYI
table1.MYD
table2.frm
table2.par
table2#P#p0.MYD
table2#P#p0.MYI
table2#P#p1.MYD
table2#P#p1.MYI
table3.frm
table3.par
table3#P#p0.MYD
table3#P#p0.MYI
table3#P#p1.MYD
table3#P#p1.MYI
The following is producing an error:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.06 sec)
mysql> use test;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_test |
+---------------------------+
| table1 |
| table2 |
| table3 |
+---------------------------+
3 rows in set (0.00 sec)
mysql> explain table1;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| a | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> explain table2;
ERROR 1017 (HY000): Can't find file: 'table2' (errno: 2)
mysql> explain table3;
ERROR 1017 (HY000): Can't find file: 'table3' (errno: 2)
mysql> check TABLE table2;
+--------------------------+-------+----------+--------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------------------+-------+----------+--------------------------------------------------+
| test.table2 | check | Error | Can't find file: 'table2' (errno: 2) |
| test.table2 | check | error | Corrupt |
+--------------------------+-------+----------+--------------------------------------------------+
2 rows in set (0.00 sec)
I checked the permissions and everything looks fine. I tried repair but that didn't seem to work either. Is there anything that can be done?
The server you are porting them to might not have partioning enabled.
Try SHOW VARIABLES LIKE '%partition%'; and check the value of the variable have_partioning or have_partition_engine (depending on your version of mysql).
Further information can be found in the documentation.