Netsuitescript 2.x how to load custome record in map/reduce - netsuite2.com

There are two custom record c1 and c2
me need to be fetch data from c2 based on record c1 item and subsidiaries internal id, after that if get the response the update record c1.
i have tried the search.create for this but its not working ( to load the all record in c1 )

Related

Select the child node in Oracle xmltype

Requirement is to display the Contact details stored in xmlformat.
My dataset as below:
Id XMldata
123 "<row id="123"><c1>Home</c1><c1 m="2">Office</c1><c1 M="3">Personal</c1><c2>+91</c2><c2 m="2">+65</c2><c2 m="3">+1</c2><c3>9900990090</c3><c3 m="2">55667788</c3><c3 m="3">123789073</c3><c4>Test element</c4></row>"
I need to build a select query to select child node matching Office contact details and to view the output in the below format:
Id C1 C2 C3
123 Office +65 55667788

Populate the columns of a Hive SQL query with results of another query

Apache Hive (version 1.2.1000.2.6.5.0-292)
I have a table, A, that has a large number of columns. I'm trying to select only the columns that I need from A and the columns I want live in a key-value pair table, B. (Example below). I can query B to get the columns I need, but I'm struggling to put the output of this sql query as the columns of the query used in A. Is there a way to do this in one sql query? I can write a python program to do this to create the SQL, but I'd rather have it in just one query for simplicity to the end-user.
DDL for tables
create table A (
a1 string,
a2 string,
a3 string,
b1 string,
b2 string,
b3 string,
)
create table B (
key string,
value string,
)
Data in table B (key value table). It should be noted that the data in the column value cannot be inferred upon by the corresponding value in column key. I have written them as a1,a2 for simplicity.
key,value
a,a1
a,a2
a,a3
b,b1
b,b2
b,b3
Query to get the correct columns = select value from B where key='a'
When you merge the results from this query with the Table A query you should get this sql statement
select a1,a2,a3 from A
As you can see, we are trying to derive the columns used in Table A
My first attempt doesn't work:
select
(select value from B where key='a')
from A
What's the right way to do this?
Thanks in advance!
You can try to generate query and write to file. Once done, you can call in existing hive hql using source command:
Here is sample queries by taking your example:
Create table and dummy data:
CREATE EXTERNAL TABLE IF NOT EXISTS a_table(
a1 string,
a2 string,
a3 string,
b1 string,
b2 string,
b3 string)
LOCATION '/user/xyz/a_table';
insert into table a_table
VALUES ('a11', 'a12', 'a13','b11','b12','b13'), ('a21', 'a22', 'a23','b21','b22','b23');
CREATE EXTERNAL TABLE IF NOT EXISTS b_table (
key string,
value string
)
LOCATION '/user/xyz/b_table';
insert into table b_table
VALUES ('a', 'a1'), ('a','a2'),('a','a3'), ('b', 'b1'), ('b','b2'),('b','b3');
Validate data into table:
select * from a_table;
OK
a11 a12 a13 b11 b12 b13
a21 a22 a23 b21 b22 b23
Time taken: 0.124 seconds, Fetched: 2 row(s)
select * from b_table;
OK
a a1
a a2
a a3
b b1
b b2
b b3
Time taken: 0.15 seconds, Fetched: 6 row(s)
This is hive hql part to generate statement based on given key and then using source to run query:
insert overwrite local directory '/home/xyz/temp_hql/out'
select concat_ws(" ", "select",concat_ws("," , collect_list(value)), "from a_table")
from b_table where key = 'a';
source /home/xyz/temp_hql/out/000000_0;
OK
a11 a12 a13
a21 a22 a23
insert overwrite local directory '/home/xyz/temp_hql/out'
select concat_ws(" ", "select",concat_ws("," , collect_list(value)), "from a_table")
from b_table where key = 'b';
source /home/xyz/temp_hql/out/000000_0;
OK
b11 b12 b13
b21 b22 b23

comparing values from two oracle table columns and getting starting value

I Have oracle table with data as shown below.
column1 column2
A1 B1
B1 C1
C1 D1
I need to get A1 value from D1. I have to implemet this in View. Need to traverse using as D1 as input and get C1 and get B1 from C1 and finally A1 using B1
Please help.
Not sure what kind of view you are looking to create; if you are thinking of passing 'A1' as an input to the view, there is no such thing in Oracle as far as I know, you would need to use a cursor for that.
The following SELECT statement can be used as an inline view (a subquery) and you can make the 'D1' value at the end of it into a bind variable if needed.
select column1
from test_data
where connect_by_isleaf = 1
connect by column2 = prior column1
start with column2 = 'D1'
;

Update Column of a Hive Table without using Sub query

This is a question regarding updating a new column in a Hive table. Since I think Hive does not allow to update a column of an existing table using subqueries, I wanted to ask what will be the best way to achieve the following update operation.
I have the following two example tables:
Table A:
KeyId ValId Val
W1 V1 10
W2 V2 20
Table B:
KeyId ValId Val
W1 V1 10
W1 V1 30
W1 V3 40
W1 V4 50
W2 V2 0
W2 V2 50
W2 V2 70
W2 V4 80
I want to create another column in Table A, lets say avgVal that takes the KeyId and ValId in each row in Table A and takes the average of Val for those corresponding KeyId and ValId in Table B. Thus, my final output table should look like:
Updated Table A:
KeyId ValId Val avgVal
W1 V1 10 20
W2 V2 20 40
Please let me know if the question is not clear.
It seems you are trying to get aggregate values in table A from table B. In that case you cannot have "val" column in table A because after aggregation which val from table B do you expect in table A?
Assuming that was genuine mistake, and you remove "val" column from table a, your insert statement for table a should look like this:
insert into table table_a select keyid,valid,avg(val) from table_b group by keyid,valid
You can use below query to get avg of data in Table_B corresponding to row in table_A :-
select t1.keyid, t1.valid , t1.val , avgval from table_A t1 left join
(select keyid as k , valid as v, avg(val) as avgval from Table_B group by keyid,valid )temp
on k=t1.keyid and t1.valid=v;
You have to check the table_A is updatable to change the schema else you can make other table to load the data.

how to insert multiple rows from a source table into a single row in target table using cursor in oracle [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can multiple rows be concatenated into one in Oracle without creating a stored procedure?
create table pr_info(
pr_ref varchar2(10),
pr_text varchar2(3),
pr_key varchar2(12)
)
This table contains the data in the following format
pr_ref pr_text pr_key
a1 abc qwertyui01
a1 def qwertyui02
b1 aaa zxcvbnmj01
b1 bbb zxcvbnmj02
b1 ccc zxcvbnmj03
That is if the pr_text is more than 3 characters long then the record is split and placed in a new record with same pr_ref but different pr_key(in this case the first 8 characters will remain the same but the last two character will signify the sequence of the record)
So now i need to put the data of this table into a new table which has the following sprecification
create table pv_cus(pv_ref vrachar2(10),pv_text varchar2(100))
So basically i need to concatenate the rows belonging to same person from the source table and put it in one row in target table.
pv_ref pv_text
a1 abc,def
b1 aaa,bbb,ccc
Procedural approach
DECLARE
type pv_ref_t is TABLE of pv_cus.pv_ref%type;
type pv_text_t is TABLE of pv_cus.pv_text%type;
v_pv_ref_tab pv_ref_t;
v_pv_text_tab pv_text_t;
v_last_pr_ref pr_info.pr_ref%type;
BEGIN
v_pv_ref_tab := pv_ref_t();
v_pv_text_tab := pv_text_t();
FOR rec in (SELECT pr_ref, pr_text FROM pr_info order by pr_ref, pr_key)
LOOP
IF v_last_pr_ref IS NULL
OR v_last_pr_ref != rec.pr_ref
THEN
v_last_pr_ref := rec.pr_ref;
v_pv_ref_tab.extend(1);
v_pv_text_tab.extend(1);
v_pv_ref_tab(v_pv_ref_tab.last) := rec.pr_ref;
v_pv_text_tab(v_pv_text_tab.last) := rec.pr_text;
ELSE
-- tbd: check length of v_pv_text_tab(v_pv_text_tab.last)
v_pv_text_tab(v_pv_text_tab.last) := v_pv_text_tab(v_pv_text_tab.last) || ',' || rec.pr_text;
END IF;
END LOOP;
FORALL i in 1..v_pv_ref_tab.last
INSERT INTO pv_cus (pv_ref, pv_text) VALUES(v_pv_ref_tab(i), v_pv_text_tab(i))
;
END;
/

Resources