Teradata BTEQ Export Script Resulting Invalid Character in O/P File - teradata

Here is my simple BTEQ Script
.LOGON 127.0.0.1/tduser,tduser
.EXPORT DATA FILE=C:\Documents and Settings\Owner\Desktop\Study\Google Drive\TD\BTEQ\Exported_File.txt
SELECT account_number
FROM samples.accounts
WHERE balance_current < 500 ;
.EXPORT RESET
.QUIT
=====================================================================================
The output of the script:
BTEQ 12.00.00.01 Tue Mar 26 19:58:59 2013
+---------+---------+---------+---------+---------+---------+---------+----
.LOGON 127.0.0.1/tduser,
*** Logon successfully completed.
*** Teradata Database Release is 12.00.00.10
*** Teradata Database Version is 12.00.00.10
*** Transaction Semantics are BTET.
*** Character Set Name is 'ASCII'.
*** Total elapsed time was 1 second.
+---------+---------+---------+---------+---------+---------+---------+----
.EXPORT DATA FILE=C:\Documents and Settings\Owner\Desktop\Study\Google Driv
e\TD\BTEQ\Exported_File.txt
*** To reset export, type .EXPORT RESET
+---------+---------+---------+---------+---------+---------+---------+----
SELECT account_number
FROM samples.accounts
WHERE balance_current < 500 ;
*** Success, Stmt# 1 ActivityCount = 4
*** Query completed. 4 rows found. One column returned.
*** Total elapsed time was 1 second.
+---------+---------+---------+---------+---------+---------+---------+----
.EXPORT RESET
*** Output returned to console.
+---------+---------+---------+---------+---------+---------+---------+----
.QUIT
*** You are now logged off from the DBC.
*** Exiting BTEQ...
*** RC (return code) = 0
=====================================================================================
Once, I check the file it shows invalid character's in the text file. Any possible workaround? Unicode problem? I am not sure.I even tried pasting the file content below, but its empty.
Thanks in advance.

Please use below command for export in bteq :
.EXPORT REPORT FILE=filename...
I had faced the same issue with data file . After changing to this , it worked.

Try enclosing your filename in double quotes because of the whitespace in the path to the actual file.
Original
.EXPORT DATA FILE=C:\Documents and Settings\Owner\Desktop\Study\Google Drive\TD\BTEQ\Exported_File.txt
Revised
.EXPORT DATA FILE="C:\Documents and Settings\Owner\Desktop\Study\Google Drive\TD\BTEQ\Exported_File.txt"

change as below..
.EXPORT REPORT FILE=filename...

Related

Cannot set a RobotFramework dictionary

I wrote this simple minimal script to show how I suffer:
main.robot
Library Collections
Library BuiltIn
Library String
*** Variables ***
&{info} Create Dictionary
*** Test Cases ***
Case_00_Initialization
Log Hello 1 WARN
Set To Dictionary ${info} field1=A sample string
Log Hello 2 WARN
Running this code by
python -m robot -L TRACE --NoStatusRC main.robot
Gives me errors:
[ ERROR ] Error in file 'C:\test\main.robot' on line 7: Setting variable '&{info}' failed: Invalid dictionary variable item 'Create Dictionary'. Items must use 'name=value' syntax or be dictionary variables themselves.
==============================================================================
Main
==============================================================================
[ WARN ] Hello 1
Case_00_Initialization | FAIL |
No keyword with name 'Set To Dictionary' found.
------------------------------------------------------------------------------
Main | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\test\output.xml
Log: C:\test\log.html
Report: C:\test\report.html
The application is supposed to set a variable info in the initialization and it will be used in the next test cases. I do not want to use Set Global Variable however.
Please note that this is a minimal working example, do not suggest to set field1 at Variables section. It is not possible. Even that one will not solve the problem of No keyword with name 'Set To Dictionary' found.
In the Variables section you cannot use keywords - and this is exactly what you did with the Create Dictionary there.
You can add some key:values to it (like "field" , but you don't allow us that ;), or - you can initialize it to be an empty dictionary (e.g. like {} in python). The later is done by passing the special value &{Empty}:
*** Variables ***
&{info} &{Empty}
I eventually found what is wrong. I was missing the line for *** Settings *** I couldn't imagine that it does matter. Shame that RF does not have many full examples online.
This is the working code:
*** Settings ***
Library Collections
*** Variables ***
&{info}
*** Test Cases ***
Case_00_Initialization
Log Hello 1 WARN
Set To Dictionary ${info} field1=A sample string
Log Hello 2 WARN

RobotFramework: empty variable check suddenly not working anymore

I'm playing around with command-line arguments and had something working both with / without giving a command-line argument, but suddenly it starts failing if I don't give a command-line argument.
On https://groups.google.com/g/robotframework-users/c/_5Usp-K4Dlw?pli=1 I read that adding a space before the variable and comparing it to a value like this '${ VAR}'==<value> should work to check if a variable is existing or not.
The code-snippet that was working before is:
*** Test Cases ***
My test
[Documentation] test to check if the SUT reacts as expected
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test} Log To Console VAR == test
After changing the code to (Removed '[Documentation]' since it was copied from another test):
*** Test Cases ***
My test
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test}
... Log To Console VAR == test
it suddenly started failing with: Variable '${ VAR}' not found. errors.
And after changing it back to the original it still fails.
I can't figure what I did wrong in the change.
Note: The company I'm working for uses RobotFramework version 3.0.4 (yes I know ancient)
Managed to solve it by adding ${VAR} with some default value to a *** Variables *** list. But still I don't understand why it was originally working without that list.
Here is how your test should look like if you want to check if variable is empty and do something based on that.
*** Variables ***
${VAR}= test
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is empty
... ELSE Log To Console Variable is not empty
If you want variable default value to be empty and execute some keyword only if it comes from command line set variable as empty, for example:
*** Variables ***
${VAR}= ${EMPTY}
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is not set
... ELSE Log To Console Variable is ${VAR}
Run your test from command-line without passing variable
$ robot sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is not set
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Now, run with passing variable
$ robot -v VAR:test sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is test
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
P.S. About space inside variable, I think it's just typo in Google Groups. If it was working then variable might be globally accessible or defined somewhere else.

Teradata BTEQ error

I am trying to run the below bteq script in unix.
BTEQ -- Update.txt
.LOGON i.p/username,password
.set width 132
.set errorout stdout
sel date, time;
.set maxerror 1
Nonsequenced validtime
update SCHEMA_1.TABLE_1
set ef_dtm = period( timestamp '1900-01-01 00:00:00.999999',
end(ef_dtm))
where begin(ef_dtm) > CURRENT_TIMESTAMP
and end(ef_dtm) = to_date('12/31/9999', 'mm/dd/yyyy')
.quit
But i am getting the below error
*** Failure 3706 Syntax error: Invalid use of JSON entity reference syntax on non-JSON type.
Statement# 1, Info =0
Exiting BTEQ... RC (return code) = 8
Please note that if I run the update statement along with nonsequenced
valid time directly in SQL Assistant, it works without any issue.
Can you please help me fix this?
Let me know if you need any more info.
User semicolon at the end of update statement.

teradata export query using cmd windows not working

new post :
i already read tutorial and i found this script
.LOGMECH LDAP;
.LOGON xx.xx.xx.xx/username,password;
.LOGTABLE dbname.LOG_tablename;
DATABASE dbname;
.BEGIN EXPORT SESSIONS 2;
.EXPORT OUTFILE D:\test.txt
MODE RECORD format text;
select a.my_date,b.name2,a.value from dbsource.tablesource a
inner join dbname.ANG_tablename b
on a.name1=b.name2
where value=59000
and a.my_date >= 01/12/2015
;
.END EXPORT;
.LOGOFF;
but it is like not working
D:\>bteq < dodol.txt
BTEQ 15.00.00.00 Tue Jan 05 14:40:52 2016 PID: 4452
+---------+---------+---------+---------+---------+---------+---------+----
.LOGMECH LDAP;
+---------+---------+---------+---------+---------+---------+---------+----
.LOGON xx.xx.xx.xx/username,
*** Logon successfully completed.
*** Teradata Database Release is 13.10.07.12
*** Teradata Database Version is 13.10.07.12
*** Transaction Semantics are BTET.
*** Session Character Set Name is 'ASCII'.
*** Total elapsed time was 4 seconds.
+---------+---------+---------+---------+---------+---------+---------+----
.LOGTABLE dbname.LOG_tablename;
*** Error: Unrecognized command 'LOGTABLE'.
+---------+---------+---------+---------+---------+---------+---------+----
DATABASE dbname;
*** New default database accepted.
*** Total elapsed time was 2 seconds.
+---------+---------+---------+---------+---------+---------+---------+----
.BEGIN EXPORT SESSIONS 2;
*** Error: Unrecognized command 'BEGIN'.
+---------+---------+---------+---------+---------+---------+---------+----
.EXPORT OUTFILE D:\test.txt
*** Warning: No data format given. Assuming REPORT carries over.
*** Error: Expected FILE or DDNAME keyword, not 'OUTFILE'.
+---------+---------+---------+---------+---------+---------+---------+----
MODE RECORD format text;
MODE RECORD format text;
$
*** Failure 3706 Syntax error: expected something between the beginning of
the request and the 'MODE' keyword.
Statement# 2, Info =6
*** Total elapsed time was 1 second.
+---------+---------+---------+---------+---------+---------+---------+----
select a.my_date,b.name2,a.value from dbsource.tablesource a
inner join dbname.ANG_tablename b
on a.name1=b.name2
where value=59000
and a.my_date >= 01/12/2015
;
old post :
I am new in teradata, i have found mload to upload big data, now i have question, is there option to use cmd ( win7 ) to export data from teradata to xxx.txt
--- sample
select a.data1,b.data2,a.data3 from room1.REPORT_DAILY a
inner join room1.andaikan_saja b
on a.likeme=b.data2
where revenue=30000
and content_id like '%super%'
and a.trx_date >= 01/12/2015
;
this is my mload up.txt
.LOGMECH LDAP;
.LOGON xx.xx.xx.xx/username,mypassword;
.LOGTABLE mydatabase.LOG_my_table;
SET QUERY_BAND = 'ApplicationName=TD-Subscriber-RechargeLoad; Version=01.00.00.00;' FOR SESSION;
.BEGIN IMPORT MLOAD
TABLES mydatabase.my_table
WORKTABLES mydatabase.WT_my_table
ERRORTABLES mydatabase.ET_my_table mydatabase.UV_my_table;
.LAYOUT LAYOUT_DATA INDICATORS;
.FIELD number * VARCHAR(20);
.DML LABEL DML_INSERT;
INSERT INTO mydatabase.my_table
(
number =:number
);
.IMPORT INFILE "D:\folderdata\data.txt"
LAYOUT LAYOUT_DATA
FORMAT VARTEXT
APPLY DML_INSERT;
.END MLOAD;
.LOGOFF &SYSRC;
i need solution to export file to my laptop, just like my script that i put ---sample title ....
i use that script from teradasql, and i am search for cmd script
If it's just a few MB and an adhoc export you can use SQL Assistant: Set the delimiter in Tools-Options-Export/Import, maybe modify the settings in Tools-Options-Export and then click File-Export Results before submitting your Select. (Similar in TD Studio)
Otherwise the easiest way to extract data in a readable delimited format is TPT, either Export for large amounts of data (GBs) or SQL Selector (MBs). TPT is available for most Operating Systems including Windows.
There's a nice User Guide with lots of example scripts:
Job Example 12: Extracting Rows and Sending Them in Delimited Format
In your case you'll define a generic template file like this:
DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export rows from a Teradata table to a delimited file'
(
APPLY TO OPERATOR ($FILE_WRITER() ATTR (Format = 'DELIMITED'))
SELECT * FROM OPERATOR ($SELECTOR ATTR (SelectStmt = #ExportSelectStmt));
);
Change $SELECTOR to $EXPORT for larger exports.
Then you just need a job variable file like this:
SourceTdpId = 'your system'
,SourceUserName = 'your user'
,SourceUserPassword = 'your password'
,FileWriterFileName = 'xxx.txt'
,ExportSelectStmt = 'select a.data1,b.data2,a.data3 from room1.REPORT_DAILY a
inner join room1.andaikan_saja b
on a.likeme=b.data2
where revenue=30000
and content_id like ''%super%''
and a.trx_date >= DATE ''2015-12-01'' -- modified this to a valid date literal
;'
The only bad part is that you have to double any single quotes within your select, e.g. '%super%' -> ''%super%''.
Finally you run a cmd:
tbuild -f your_template_file -v your_job_var_file
Depending on the volume of data you wish to extract from Teradata you can use Teradata BTEQ or the Teradata Parallel Transport (TPT) utility with the EXPORT operator from the command line to extract the data.
The TPT utility is the eventual replacement for the legacy Teradata Load and Unload utilities (FastLoad, MultiLoad, FastExport, and TPump) and provides an easier mechanism to produce delimited flat files over FastExport. TPT is fairly flexible and effective for exporting large volumes of data to channel or network attached clients.
Teradata BTEQ can perform lightweight load and unload functions. The BTEQ manual is pretty good at providing you an overview of how to use the various commands to produce a semi-structured report or data extract. It doesn't have a simple command to produce a delimited flat file. If you review the manual's overview of the EXPORT command you should get a good feel for how BTEQ behaves when working with channel or network attached clients.

Using Variables in Variable definition

I am trying to get variables into variables but it wont work. I searched google and tried a lot of stuff but it did not wor out.
I hope this question ist not "dumb":
What am I doing wrong ?
*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
*** Variable ***
${year} Get Time return year
${month} Get Time return month
${day} Get Time return day
${output} ${CURDIR}\Testing\Tests\SRV\csdb_#{year}-#{month}-#{day}.log
*** Testcases ***
Textfile should have a line saying the service is started
${errors} = Grep File ${output} Test
From the robot framework user's guide:
The most common source for variables are Variable tables in test case
files and resource files. Variable tables are convenient, because they
allow creating variables in the same place as the rest of the test
data, and the needed syntax is very simple. Their main disadvantages
are that values are always strings and they cannot be created
dynamically.
In order to do what you want, you'll need to define the variables in a keyword. For example:
*** Keywords ***
Get Output
${year}= Get Time year
${month}= Get Time month
${day}= Get Time day
${output}= Set variable ${CURDIR}/Testing/Tests/SRV/csdb_${year}-${month}-${day}.log
[Return] ${output}
*** Testcases ***
Textfile should have a line saying the service is started
${output}= Get Output
${errors} = Grep File ${output} Test
Note: you can fetch all three parts of the data in a single call to the keyword, like so:
${year} ${month} ${day}= Get Time year month day
It's a bit hard to read with the space-separated format, but the variable names must each be separated by two or more spaces, but "year month day" should have only one.

Resources