Parsing and getting specific values from CSV string - vb.net

I am having a string in CSV format. Please see my earlier question
Parsing CSV string and binding it to listbox
I can add new values to it by some mechanism. Everything will be same except the new values will have numeric part = 0. Take example
I have this exsiting CSV string
1 , abc.txt , 2 , def.doc , 3 , flyaway.txt
Now by some mechanism i added two more files Superman.txt and Spiderman.txt to the existing string. Now it became
1 , abc.txt , 2 , def.doc , 3 , flyaway.txt, 0, Superman.txt, 0 , Spiderman.txt
What i am doing here is that this csv string is paased into SP where its splitted and inserted to db. So for inserting I have to take the files with numeric part 0 only rest will be omiited .Which will be further then converted into CSV string
Array will look like this
str[0]="1"
str[1]="abc.txt"
str[2]="2"
str[3]="def.doc "
str[4]="3"
str[5]="flyaway.txt"
str[6]="0"
str[7]="Superman.txt"
str[8]="0"
str[9]="Spiderman.txt"
So at last i want to say my input will be
1 , abc.txt , 2 , def.doc , 3 , flyaway.txt, 0, Superman.txt, 0 , Spiderman.txt
Desired Output:
0, Superman.txt, 0 , Spiderman.txt

If your new values are always being added to the end of the input, all you need to do is search the string for the first 0 and then return it and everything after it using string.Substring(Int32).

Related

Data type unexpectedly changed during MERGE

I have a temporary table into which 24K data records are imported with quotes (") around all of the fields and using a pipe (|) as the field delimiter. I'm running a MERGE to UPDATE/INSERT data into another table and using the REPLACE to strip the quotes as it runs. All of that works perfectly EXCEPT, ONE field seems to convert the data from text to scientific notation ("600E0" becomes 6.00E+02). BOTH fields are nvarchar(20) in their respective tables and I would expect the quoted text to translate to unquoted text.
tmpEmployee.tmpCode = REPLACE(source.tmpCode, '"','')
I even tried changing the data type in both tables to char(8). Still no joy!!!
What am I doing wrong?
UPDATE:
MERGE tmpEmployee
USING tempEmployees as source
ON source.tmpEmpNum = tmpEmployee.tmpEmpNum
WHEN MATCHED
THEN UPDATE SET
tmpEmployee.tmpUserID = LOWER(REPLACE(source.tmpUserID, '"',''))
, tmpEmployee.tmpLastName = dbo.properCase(REPLACE(source.tmpLastName, '"',''))
, tmpEmployee.tmpFirstName = dbo.properCase(REPLACE(source.tmpFirstName, '"',''))
, tmpEmployee.tmpEmail = LOWER(REPLACE(source.tmpEmail, '"',''))
, tmpEmployee.tmpPhone = REPLACE(source.tmpPhone, '"','')
, tmpEmployee.tmpCode = REPLACE(source.tmpCode, '"','')
WHEN NOT MATCHED
THEN INSERT (tmpUserID, tmpLastName, tmpFirstName, tmpEmail, tmpPhone, tmpCode)
VALUES (LOWER(REPLACE(source.tmpUserID, '"',''))
, dbo.properCase(REPLACE(source.tmpLastName, '"',''))
, dbo.properCase(REPLACE(source.tmpFirstName, '"',''))
, LOWER(REPLACE(source.tmpEmail, '"',''))
, REPLACE(source.tmpPhone, '"','')
, REPLACE(source.tmpCode, '"','');

user input , user inputs data into the list

I have a eval solution , that the user need to input the names of the people and give a certain value , i am trying to make it work but the input part is not working.
preferencia(ana,joana,1).
preferencia(ana,rui,-1).
preferencia(ana,maria,1).
preferencia(ana,jose,-1).
preferencia(ana,tiago,-1).
preferencia(ana,andre,1).
preferencia(joana,rui,2).
preferencia(joana,maria,1.5).
preferencia(joana,jose,-1).
preferencia(joana,tiago,1).
preferencia(joana,andre,-1).
preferencia(rui,maria,1).
preferencia(rui,jose,-1).
preferencia(rui,tiago,1).
preferencia(rui,andre,1).
preferencia(maria,jose,-1).
preferencia(maria,tiago,1).
preferencia(maria,andre,-1).
preferencia(jose,tiago,1).
preferencia(jose,andre,1).
preferencia(tiago,andre,-1).
preferencia(X,Y,D):-preferencia(Y,X,D),!. % reverse preferenciaance
% representation: S is a list of persons
% evaluation function:
eval([_],0).
eval([Name1,Name2|R],DS):-
preferencia(Name1,Name2,D),
eval([Name2|R],DR),
DS is D+DR.
start :- write('Pick 2 Person to make a group '), read(X), eval([X,X|R],DS).
i want the user to input 2 names via console , so i want is the console working like this , "Pick 2 Person to make a group" the user inputs the (ex. rui , maria) , and return the value of their preference. If i input eval([rui,mariaR],DS) it returns the value 1 , but this in only in static way , i want the user being able to select 2 names and return their preference level. I believe the main error is the start function , thanks

data processing in pig , with tab separate

I am very new to Pig , so facing some issues while trying to perform very basic processing in Pig.
1- Load that file using Pig
2- Write a processing logic to filter records based on Date , for example the lines have 2 columns col_1 and col_2 ( assume the columns are chararray ) and I need to get only the records which are having 1 day difference between col_1 and col_2.
3- Finally store that filtered record in Hive table .
Input file ( tab separated ) :-
2016-01-01T16:31:40.000+01:00 2016-01-02T16:31:40.000+01:00
2017-01-01T16:31:40.000+01:00 2017-01-02T16:31:40.000+01:00
When I try
A = LOAD '/user/inp.txt' USING PigStorage('\t') as (col_1:chararray,col_2:chararray);
The result I am getting like below :-
DUMP A;
(,2016-01-03T19:28:58.000+01:00,2016-01-02T16:31:40.000+01:00)
(,2017-01-03T19:28:58.000+01:00,2017-01-02T16:31:40.000+01:00)
Not sure Why ?
Please can some one help me in this how to parse tab separated file and how to covert that chararray to Date and filter based on Day difference ?
Thanks
Convert the columns to datetime object using ToDate and use DaysBetween.This should give the difference and if the difference == 1 then filter.Finally load it hive.
A = LOAD '/user/inp.txt' USING PigStorage('\t') as (col_1:chararray,col_2:chararray);
B = FOREACH A GENERATE DaysBetween(ToDate(col_1,'yyyy-MM-dd HH:mm:ss'),ToDate(col_2,'yyyy-MM-dd HH:mm:ss')) as day_diff;
C = FILTER B BY (day_diff == 1);
STORE C INTO 'your_hive_partition' USING org.apache.hive.hcatalog.pig.HCatStorer();

apache hive loads null values instead of intergers

I am new to apache hive and was running queries on sample data which is saved in a csv file as below:
0195153448;"Classical Mythology";"Mark P. O. Morford";"2002";"Oxford University Press";"//images.amazon.com/images/P/0195153448.01.THUMBZZZ.jpg";"http://images.amazon.com/images/P/0195153448.01.MZZZZZZZ.jpg";"images.amazon.com/images/P/0195153448.01.LZZZZZZZ.jpg"
and the table which i created is of form
hive> describe book;
OK
isbn bigint
title string
author string
year string
publ string
img1 string
img2 string
img3 string
Time taken: 0.085 seconds, Fetched: 8 row(s)
and the script which I used to create the table is:
create table book(isbn int,title string,author string, year string,publ string,img1 string,img2 string,img3 string) row format delimited fields terminated by '\;' lines terminated by '\n' location 'path';
When I try to retrieve the data from the table by using the following query:
select *from book limit 1;
I get the following result:
NULL "Classical Mythology" "Mark P. O. Morford" "2002" "Oxford University Press" "http://images.amazon.com/images/P/0195153448.01.THUMBZZZ.jpg" "images.amazon.com/images/P/0195153448.01.MZZZZZZZ.jpg" "images.amazon.com/images/P/0195153448.01.LZZZZZZZ.jpg"
Even though I specify the first column type as int or bigint the data into the table is getting loaded as NULL.
I tried searching on the internet and could figure out that I have to specify the row delimiter. I used that too but no change in the data from the table.
Is there anything that I am making a mistake... Please help.

using multiple parameters in append query in Access 2010

I have been trying to get an append query to work but I keep getting an error stating that 0 rows are being appended whenever I use more than 1 parameter in the query. This is for a
The table in question has 1 PK which is a GUID [which is generating values with newid()] and one required field (Historical) which I am explictly defining in the query.
INSERT INTO dbo_sales_quotas ( salesrep_id
, [year]
, territory_id
, sales_quota
, profit_quota
, product_super_group_uid
, product_super_group_desc
, class_9
, Historical
, sales_quotas_UID )
SELECT dbo_sales_quotas.salesrep_id
, dbo_sales_quotas.Year
, dbo_sales_quotas.territory_id
, dbo_sales_quotas.sales_quota
, dbo_sales_quotas.profit_quota
, dbo_sales_quotas.product_super_group_uid
, dbo_sales_quotas.product_super_group_desc
, dbo_sales_quotas.class_9
, dbo_sales_quotas.Historical
, dbo_sales_quotas.sales_quotas_UID
FROM dbo_sales_quotas
WHERE (((dbo_sales_quotas.salesrep_id)=[cboSalesRepID])
AND ((dbo_sales_quotas.Year)=[txtYear])
AND ((dbo_sales_quotas.territory_id)=[txtTerritoryID])
AND ((dbo_sales_quotas.sales_quota)=[txtSalesQuota])
AND ((dbo_sales_quotas.profit_quota)=[txtProfitQuota])
AND ((dbo_sales_quotas.product_super_group_uid)=[cboProdSuperGroup])
AND ((dbo_sales_quotas.product_super_group_desc)=[txtProductSuperGroupDesc])
AND ((dbo_sales_quotas.class_9)=[cboClass9])
AND ((dbo_sales_quotas.Historical)='No')
AND ((dbo_sales_quotas.sales_quotas_UID)='newid()'));
Even if I assign specific values, I still get a 0 rows error except when I reduce the number of parameters to 1 (which it then works perfectly regardless of which parameter) I have verified that the parameters have the correct formats.
Can anyone tell me what I'm doing wrong?
Break out the SELECT part of your query and examine it separately. I'll suggest a simplified version which may be easier to study ...
SELECT
dsq.salesrep_id,
dsq.Year,
dsq.territory_id,
dsq.sales_quota,
dsq.profit_quota,
dsq.product_super_group_uid,
dsq.product_super_group_desc,
dsq.class_9,
dsq.Historical,
dsq.sales_quotas_UID
FROM dbo_sales_quotas AS dsq
WHERE
dsq.salesrep_id=[cboSalesRepID]
AND dsq.Year=[txtYear]
AND dsq.territory_id=[txtTerritoryID]
AND dsq.sales_quota=[txtSalesQuota]
AND dsq.profit_quota=[txtProfitQuota]
AND dsq.product_super_group_uid=[cboProdSuperGroup]
AND dsq.product_super_group_desc=[txtProductSuperGroupDesc]
AND dsq.class_9=[cboClass9]
AND dsq.Historical='No'
AND dsq.sales_quotas_UID='newid()';
I wonder about the last 2 conditions in the WHERE clause. Is the Historical field type bit instead of text? Does the string 'newid()' match sales_quotas_UID in any rows in the table?