Blank rows not coming - u-sql

After running the below code i am getting only rows where is present and not the rows where just ID is present.
Is there any problem with the extraction of file.
DROP VIEW IF EXISTS dbo.Consolidated;
CREATE VIEW IF NOT EXISTS dbo.Consolidated
AS
EXTRACT Statement
FROM "adl:///2016/08/12/File_name.csv"
USING Extractors.Csv(silent : true, quoting : true, nullEscape : "/N");
#Temp =
SELECT *
FROM Consolidated;
OUTPUT #Temp
TO "adl://arbit/new_cont_check.csv"
USING Outputters.Csv();

So your number of columns vary? If yes, try using a user-defined extractor. An example of a user-defined extractor where the number of columns vary can be seen # Using User-Defined Extractor - FlexExtractor.

You have added the silent: true argument to your USING clause meaning the EXTRACT will not fail or even complain if the rows don't quite match your schema definition. This is the intended behaviour and probably what you want for this example. In order to pick up the other rows, you can use OUTER UNION, like in this recent example:
Another working example similar to yours:
#input =
EXTRACT ControllerID int?,
ParameterID int?,
MeasureDate DateTime,
Value float
FROM "/input/input56.csv"
USING Extractors.Csv(silent : true, quoting : true, nullEscape : "/N", skipFirstNRows : 1)
OUTER UNION ALL BY NAME ON ( ControllerID )
EXTRACT ControllerID int?
FROM "/input/input56.csv"
USING Extractors.Csv(silent : true, quoting : true, nullEscape : "/N", skipFirstNRows : 1);
OUTPUT #input
TO "/output/output.txt"
USING Outputters.Tsv(quoting : false);
I used this sample file and got these results:
NB I have changed the nullability of your columns as otherwise the OUTER UNION add default values for the .Net types as per the Sep 2016 release notes.

Related

How to get a row object from a function that return a table object in plsql?

i'm trying to get a single row and save it into a variable in PLSQL.
I'm using APEX and all is around the APEX_DATA_PARSE.PARSE() function.
As the docs said, .PARSE() should return WWV_FLOW_T_PARSER_ROW for every row of results.
What i'm trying to do is to get only one row to be saved into a variable.
This is My code:
`
DECLARE
r_columns_headers WWV_FLOW_T_PARSER_ROW; --object
BEGIN
DBMS_OUTPUT.ENABLE;
BEGIN
<<populate_headers>>
select * into r_columns_headers
from apex_application_temp_files f,
table( apex_data_parser.parse(
p_content => f.blob_content,
p_add_headers_row => 'Y',
P_SKIP_ROWS => 1,
p_max_rows => 500,
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => f.filename ) ) p
where f.name = '43300947378776117/DATALOAD_Test_data_main_v032.xlsx' and p.line_number = 2;
end populate_headers;
DBMS_OUTPUT.PUT_LINE(r_columns_headers.id);
end;
`
is just for test outside the main package that i'm writing.
The error i get is PL/SQL: ORA-00947 on row 8, on the select * into r_columns_headers section.
I don't know why i get not enough values, the fields are the same as they are the same type of object. The select return exactly one row, of a WWV_FLOW_T_PARSER_TABLE object. Not all columns are with data, someones are null, is this the problem?
I'm just at the beginning of learning plsql.
Thanks a lot
wwv_flow_t_parser_row
I'm trying to get a row into the r_columns_headers variable to access it in my program.
The "ORA-00947: not enough values" error is sometimes a bit confusing; in a PL/SQL context it can be backwards.
The problem is that you actually have too many values in your select list. You are doing:
select * into r_columns_headers
but you're joining two table expression, apex_application_temp_files as f and the unnested table as p. So the * is effectively doing:
select f.*, p.* into r_columns_headers
... and that object doesn't have fields for all the columns coming from f.
So you need to restrict it to the relevant data:
select p.* into r_columns_headers
... but that returns all of the object attributes as individual columns, not as a single object; but you can get the actual object with the value() function:
select value(p) into r_columns_headers
fiddle with a dummy object type and data as the real APEX types aren't available there.

SQLite EXISTS with UPDATE Statement

I'm using SQLite and have two tables:
Line {
Element_ID,
length
}
Element{
Element_ID,
Name
}
I want to update the parameter "length" to a certain value in Line by specifying the "Name" in Element where Element_ID is the same for Line and Element.
SQLite does not support the JOIN statement in combination with the UPDATE statement, so I've been trying various combinations of UPDATE with EXISTS without any success. Example; update length to 2 for the line with element Name 'c18':
UPDATE Line
SET length = 2
WHERE EXISTS (SELECT length FROM Line WHERE Line.Element_ID = Element.Element_ID AND Element.Name = 'c18')
Result: Error: No such column: Element.Element_ID
UPDATE Line
SET length = 2
WHERE EXISTS (SELECT length FROM Line INNER JOIN Element ON Line.Element_ID = Element.Element_ID WHERE Element.Name = 'c18')
Result: The code updates length for ALL lines (it looks like it disregards the last part in the EXISTS-statement WHERE Element.Name = 'c18'. I don't understand why this is happening, because if I only run the SELECT-statement inside the WHERE EXISTS(..) the program selects the correct line (c18).
Can anyone help me with this?
The first query doesn't work because you are referencing Element in the WHERE clause without defining it anywhere (as a table or an alias).
The second one because the subquery does not depend on the main query (it is not a correlated subquery) and therefore it has the same value for every row.
A simpler way to do this could be :
UPDATE Line SET length = 2
WHERE Element_ID in ( SELECT Element_ID FROM Element WHERE Name = 'c18' )
or to make it a bit more explicit :
UPDATE Line SET length = 2
WHERE Element_ID in ( SELECT e.Element_ID FROM Element e WHERE e.Name = 'c18' )

Query SQLite using uuid returns nothing

I'm querying a SQLite db file using the id column, which is UNIQUEIDENTIFIER type.
The two commands are :
SELECT * FROM scanned_images WHERE id = cast('5D878B98-71B2-4DEE-BA43-61D11C8EA497' as uniqueidentifier)
or
SELECT * FROM scanned_images WHERE id = '5D878B98-71B2-4DEE-BA43-61D11C8EA497'
However, the above commands both returned nothing.
I also tried:
SELECT * FROM scanned_images WHERE rowid = 1
this command returns the correct data.
There is no uniqueidentifier data type in SQLite.
According to the rules of type affinity described here in 3.1. Determination Of Column Affinity, the column's affinity is numeric.
All that this expression does:
cast('5D878B98-71B2-4DEE-BA43-61D11C8EA497' as uniqueidentifier)
is return 5.
You should have defined the column's data type as TEXT, because you have to treat it like TEXT and write the condition:
WHERE id = '5D878B98-71B2-4DEE-BA43-61D11C8EA497'
or:
WHERE id = '(5D878B98-71B2-4DEE-BA43-61D11C8EA497)'
if as shown in the image it contains surrounding parentheses.

Getting error with basic trim() function in U-SQL script

I want to apply .trim() function on a column but getting the error.
Sample data:
Product_ID,Product_Name
1, Office Supplies
2,Personal Care
I have to do some data manipulation but can't get the basic trim() function right.
#productlog =
EXTRACT Product_ID string,
Prduct_Name string
FROM "/Staging/Products.csv"
USING Extractors.Csv();
#output = Select Product_ID, Product_Name.trim() from #productlog;
OUTPUT #output
TO "/Output/Products.csv"
USING Outputters.Csv();
Error:
Activity U-SQL1 failed: Error Id: E_CSC_USER_SYNTAXERROR, Error Message: syntax error. Expected one of: '.' ALL ANTISEMIJOIN ANY AS BEGIN BROADCASTLEFT BROADCASTRIGHT CROSS DISTINCT EXCEPT FULL FULLCROSS GROUP HASH HAVING INDEXLOOKUP INNER INTERSECT JOIN LEFT LOOP MERGE ON OPTION ORDER OUTER OUTER UNION PAIR PIVOT PRESORT PRODUCE READONLY REQUIRED RIGHT SAMPLE SEMIJOIN SERIAL TO UNIFORM UNION UNIVERSE UNPIVOT USING WHERE WITH ';' '(' ')' ',' .
Try the below, afaik you need to alias trimmed fields
#productlog =
EXTRACT Product_ID string,
Prduct_Name string
FROM "/Staging/Products.csv"
USING Extractors.Csv();
#output = Select Product_ID, Product_Name.trim() as Trimmed_Product_Name from #productlog;
OUTPUT #output
TO "/Output/Products.csv"
USING Outputters.Csv();
Got it right finally, in case someone else face the same issue. U-SQL is more like C# so it will be a bit tricky for people like me, coming from pure SQL background.
Code:
#productlog =
EXTRACT Product_ID string,
Prduct_Name string
FROM "/Staging/Products.csv"
USING Extractors.Csv();
#output =
SELECT
T.Product_ID,
T.Prduct_Name.ToUpper().Trim() AS Prduct_Name
FROM #productlog AS T;
OUTPUT #output
TO "/Output/Products.csv"
USING Outputters.Csv();

Does MariaDB 10.1+ have array/collection types for variables?

Does MariaDB have anything like arrays for variables? (Not for storage into a table. Instead I was hoping to use them to hold values to be used individually in queries.)
For example:
SELECT ... WHERE x = myVAR[1];
What do you mean?
SELECT ... FROM tbl WHERE x IN (1,4,767,443)
SELECT ... FORM tbl .. -- and get any "rows"; this is like an array.
SET #variable := 123; -- not an array, but a scalar, for use thus:
SELECT ... WHERE x = #variable;

Resources