I am trying to make dynamic statements using tpt but whenever i run tpt, it ends up with following error
LOAD_OPERATOR: TPT10508: RDBMS error 2556: Duplicate match tag found. (please see following log for further detail)
Log File
--------------------------------------------------Tue 01/16/2018 20:09:57.38------------------------------------------------------------
Teradata Parallel Transporter Version 15.10.01.02 64-Bit
Job log: C:\Program Files\Teradata\client\15.10\Teradata Parallel Transporter/logs/demo_tpt_tpt_cdc_Demo_RESTORE-1379.out
Job id is demo_tpt_tpt_cdc_Demo_RESTORE-1379, running on WPKZA186003-650
Found CheckPoint file: C:\Program Files\Teradata\client\15.10\Teradata Parallel Transporter/checkpoint\demo_tpt_tpt_cdc_Demo_RESTORELVCP
This is a restart job; it restarts at step MAIN_STEP.
Teradata Parallel Transporter Update Operator Version 15.10.01.02
LOAD_OPERATOR: private log not specified
Teradata Parallel Transporter DataConnector Operator Version 15.10.01.02
FILE_READER[1]: Instance 1 directing private log report to 'dtacop-za186003-19316-1'.
FILE_READER[1]: DataConnector Producer operator Instances: 1
FILE_READER[1]: ECI operator ID: 'FILE_READER-19316'
FILE_READER[1]: Operator instance 1 processing file '\demo_tpt\DEMO_TPT_TPT_CDC_DEMO.csv'.
LOAD_OPERATOR: connecting sessions
LOAD_OPERATOR: preparing target table(s)
LOAD_OPERATOR: entering DML Phase
a
LOAD_OPERATOR: disconnecting sessions
FILE_READER[1]: Total files processed: 0.
LOAD_OPERATOR: Total processor time used = '0.3125 Second(s)'
LOAD_OPERATOR: Start : Tue Jan 16 20:10:00 2018
LOAD_OPERATOR: End : Tue Jan 16 20:10:02 2018
Job step MAIN_STEP terminated (status 12)
Job demo_tpt_tpt_cdc_Demo_RESTORE terminated (status 12)
Job start: Tue Jan 16 20:09:58 2018
Job end: Tue Jan 16 20:10:02 2018
TPT Script
USING CHARACTER SET UTF8
DEFINE JOB "demo_tpt_tpt_cdc_Demo_1516018197546"
DESCRIPTION 'Data Loading Job'
(
DEFINE SCHEMA tpt_cdc_Demo_SCHEMA
DESCRIPTION 'SCHEMA DETAILS'
(
Product_ID VARCHAR(4)
, Product_Name VARCHAR(40)
, Product_Code VARCHAR(15)
, Product_History VARCHAR(15)
, Created_Date VARCHAR(19)
, Updated_Date VARCHAR(19)
, End_Date VARCHAR(19)
);
DEFINE OPERATOR FILE_READER
DESCRIPTION 'TERADATA PARALLEL TRANSPORTER DATA CONNECTOR OPERATOR'
TYPE DATACONNECTOR PRODUCER
SCHEMA tpt_cdc_Demo_SCHEMA
ATTRIBUTES
(
VARCHAR DIRECTORY_PATH = 'C:\TeradataOffice\td2tdapp\demo_tpt\'
,VARCHAR FileName = 'C:\TeradataOffice\td2tdapp\demo_tpt\DEMO_TPT_TPT_CDC_DEMO.csv'
,VARCHAR IndicatorMode = 'N'
,VARCHAR OpenMode = 'Read'
,VARCHAR Format = #Format
,VARCHAR TextDelimiter = ','
);
DEFINE OPERATOR LOAD_OPERATOR
DESCRIPTION 'TERADATA PARALLEL TRANSPORTER LOAD OPERATOR'
TYPE UPDATE
SCHEMA tpt_cdc_Demo_SCHEMA
ATTRIBUTES
(
VARCHAR TdpId = #TargetTdpId
,VARCHAR UserName = #TargetUserName
,VARCHAR UserPassword = #TargetUserPassword
,VARCHAR TargetTable = 'TPT_Test.tpt_cdc_Demo'
,VARCHAR ErrorTable1 = 'TPT_Test.tpt_cdc_Demo_ET1'
,VARCHAR ErrorTable2 = 'TPT_Test.tpt_cdc_Demo_ET2'
,VARCHAR LogTable = 'TPT_Test.tpt_cdc_Demo_LT'
,INTEGER MaxDecimalDigits = 38
,VARCHAR SpoolMode = 'NoSpoolOnly'
,INTEGER MaxSessions=32
,INTEGER Minsessions=8
,VARCHAR DateForm='AnsiDate'
);
APPLY (' MERGE INTO TPT_TEST.tpt_cdc_Demo
USING VALUES (50,''NewTransaction'',''0024'',''50'',''2018-01-10 10:14:59'',''2018-01-10 10:14:59'',''2018-01-10 10:14:59'')
AS Dept (Product_ID, Product_Name, Product_Code, Product_History,
Created_Date, Updated_Date, End_Date)
ON Dept.Product_ID =tpt_cdc_Demo.Product_ID
WHEN MATCHED THEN UPDATE
SET End_Date = Dept.End_Date
WHEN NOT MATCHED THEN INSERT
VALUES (Dept.Product_ID, Dept.Product_Name, Dept.Product_Code, Dept.Product_History,
Dept.Created_Date, Dept.Updated_Date, Dept.End_Date);')
TO OPERATOR (LOAD_OPERATOR)
SELECT * FROM OPERATOR (FILE_READER[1]););
);
Any idea?
Related
ddl sql
create table a (
`id` bigint not null ,
`update_time` datetime
)
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
)
error msg
SQL 错误 [1105] [HY000]: errCode = 2, detailMessage = Cluster default_cluster has no available capacity
Go to the be storage directory to see the storage space
When you are loading a teradata table in bteq you can set the queryband for block level compression. This even works when you are using querygrid and inserting from a foreign server.
SET QUERY_BAND = 'BlockCompression=Yes;' UPDATE FOR SESSION;
My issue is that I am creating a table on an Aster system and then using the load to teradata function. I suspect there is a syntax call where I can set the query band as part of the load_to_teradata call but after searching the internet and through a reem of teradata documentation I haven't found anything yet.
-- Load Agg data for the YYYYMM to Teradta
SELECT SUM(loaded_row_count),SUM(error_row_count)
FROM load_to_teradata (
ON ( select
Cust_id
, cast(lst_cnf_actvy_dt_tm as date) as lst_cnf_actvy_dt
, cast(sum(str_cnt ) as INTEGER) as acct_open_brnch_use_cnt
, cast(sum(phone_cnt ) as INTEGER) as acct_open_phn_use_cnt
, cast(sum(mail_cnt ) as INTEGER) as acct_open_mail_use_cnt
, cast(sum(onlnchnl_cnt) as INTEGER) as acct_open_onln_use_cnt
, cast(sum(mblbnk_cnt ) as INTEGER) as acct_open_mbl_dvc_use_cnt
, cast(sum(acctopen_cnt) as INTEGER) as acct_open_trck_chnl_cnt
from <someDB>.<someTBL>
where acctopen_cnt > 0
and lower(lst_cnf_actvy_typ_cd) = 'acctopen'
and cast(lst_cnf_actvy_dt_tm as date) between
cast(substring('${YYYYMM}' from 1 for 4) || '-' || substring('${YYYYMM}' from 5 for 2) || '-01' as date) and
cast((cast(substring('${YYYYMM}' from 1 for 4) || '-' || substring('${YYYYMM}' from 5 for 2) || '-01' as date) + interval '1 month') - interval '1 day' as date)
and (str_cnt > 0 or phone_cnt > 0 or mail_cnt > 0 or onlnchnl_cnt > 0 or mblbnk_cnt > 0)
group by 1,2 )
TDPID('TD_RDBMS_C2T') USERNAME('${c2tUID}') PASSWORD('${c2tPWD}') ${LDAP_IND_AST_C2T}
TARGET_TABLE ( 'C2T.t_yyyymm_agg' ) LOG_TABLE ('C2T.t_yyyymm_aggLOG')
MAX_SESSIONS(120));
Was able to get the syntax for the load_to_teradata options. You can see the query_band_sess_info argument after max_sessions and before query_timeout...
load_to_teradata(
ON (source query)
TDPID('tdpid')
TARGET_TABLE('fully-qualified table name')
[ERROR_TABLES('error table'[, 'unique constraint violation table'])]
[LOG_TABLE('table name')]
Teradata QueryGrid: Aster-Teradata Connector
Loading Data From Aster Database to Teradata
Aster Database User Guide for Aster Appliances 301
[USERNAME('username')]
[PASSWORD('password')]
[LOGON_MECHANISM('TD2' | 'LDAP' | 'KRB5')]
[LOGON_DATA('mechanism-specific logon data')]
[ACCOUNT_ID('account-id')]
[TRACE_LEVEL('trace-level')]
[NUM_INSTANCES('instance-count')]
[START_INSTANCE('start-instance')]
[MAX_SESSIONS('max-sessions-number')]
[QUERY_BAND_SESS_INFO('key1=value1;key2=value2;...')]
[QUERY_TIMEOUT('timeout-in-seconds')]
[AUTO_TUNE_INSTANCES('yes'|'no')]
[WORKINGDATABASE(‘dbname’)]
[DIAGNOSTIC_MODE('All'|['GetCOPEntries','CheckConnectivity',
'CheckAuthentication','GetTPTSessions',
'TargetTableOrQuerySchema'])])
);
I'm using an External Table in Oracle 11g. I have a date field in the last column of the file. I parse that in into a TIMESTAMP column in my table definition:
CREATE TABLE e_tbl_one
(
FOPV_KEY INTEGER,
FACILITY VARCHAR2(50),
QTY_6HR NUMBER,
SECURITY_CODE NUMBER,
LOAD_DATE TIMESTAMP(0) WITH LOCAL TIME ZONE
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY MYDB_EXTERNAL_TABLE_DATA
ACCESS PARAMETERS
( records delimited by newline SKIP 1
NOBADFILE
NOLOGFILE
fields terminated by '|'
missing field values are null
(
FOPV_KEY,
FACILITY,
QTY_6HR,
SECURITY_CODE,
LOAD_DATE date 'mm/dd/yyyy hh:mi:ss am'
)
)
LOCATION (MYDB_EXTERNAL_TABLE_DATA:'e_tbl_one.txt')
)
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;
This will parse the date 11/10/2015 1:59:37 PM but not 11/10/2015 01:59:37 PM or 11/10/2015 12:45:12 PM
The log file shows:
KUP-04021: field formatting error for field LOAD_DATE
KUP-04026: field too long for datatype
KUP-04101: record 2 rejected in file /dbfs_direct/FS1/MYDB_EXTERNAL_TABLE/e_tbl_one.txt
The data for LOAD_DATE at this time was: 11/11/2015 07:28:36 am. The record in the text file is:
70581692|WS3|308|2048|11/11/2015 07:41:00 am[CRLF]
Why can't this be parsed as LOAD_DATE date 'mm/dd/yyyy hh:mi:ss am'?
I have a subquery in the select statement that I need to find a count based on the base query. If I hard code the course_id that needing the count for it works (other then the count is for just the same course not all listed) but when I change it to use the listed course_id it returns the 1054 - Unknown column error.
Error SQL
SELECT
c.course_id,
c.course_name,
(SELECT COUNT(wpt_users_id)
FROM (SELECT course_activity.wpt_users_id, course_activity.course_id, min(course_activity.course_activity_entry_dt)
FROM wpt_user_subscriptions
JOIN course_activity ON course_activity.wpt_users_id = wpt_user_subscriptions.wpt_users_id
WHERE wpt_user_subscriptions.wpt_subscription_id = 35
AND course_activity.course_id = c.course_id
GROUP BY course_activity.wpt_users_id, course_activity.course_id) sub1) as course_count
FROM `wpt_subscription_course` sc
JOIN course c ON c.course_id = sc.course_id
WHERE sc.`wpt_subscription_id` = 35
Returns: MySQL said: #1054 - Unknown column 'c.course_id' in 'where clause'
Will run SQL:
SELECT
c.course_id,
c.course_name,
(SELECT COUNT(wpt_users_id)
FROM (SELECT course_activity.wpt_users_id, course_activity.course_id, min(course_activity.course_activity_entry_dt)
FROM wpt_user_subscriptions
JOIN course_activity ON course_activity.wpt_users_id = wpt_user_subscriptions.wpt_users_id
WHERE wpt_user_subscriptions.wpt_subscription_id = 35
AND course_activity.course_id = 9
GROUP BY course_activity.wpt_users_id, course_activity.course_id) sub1) as course_count
FROM `wpt_subscription_course` sc
JOIN course c ON c.course_id = sc.course_id
WHERE sc.`wpt_subscription_id` = 35
Any thoughts to why it's not working when it's spelled correctly yet not working.
Environment specs:
[[Database server]]
Server type: MariaDB
Server version: 5.5.41-MariaDB - MariaDB Server
Protocol version: 10
[[phpMyAdmin]]
Version information: 4.4.8, latest stable version: 4.4.10
[[Web server]]
Apache/2.4.6 (CentOS) PHP/5.4.16
Database client version: libmysql - 5.5.41-MariaDB
PHP extension: mysqli Documentation
PHP version: 5.4.16
Thanks.
A bit more indentation makes it more obvious:
SELECT c.course_id, c.course_name,
( SELECT COUNT(wpt_users_id)
FROM
( SELECT ca.wpt_users_id, ca.course_id,
min(ca.course_activity_entry_dt)
FROM wpt_user_subscriptions AS wus
JOIN course_activity AS ca ON ca.wpt_users_id =
wus.wpt_users_id
WHERE wus.wpt_subscription_id = 35
AND ca.course_id = c.course_id -- HERE
GROUP BY ca.wpt_users_id, ca.course_id
) sub1
) as course_count
FROM `wpt_subscription_course` sc
JOIN course c ON c.course_id = sc.course_id -- HERE
WHERE sc.`wpt_subscription_id` = 35
I think subqueries can see tables only in the immediately surrounding query.
Maybe this works and gets the right answers??
SELECT c.course_id, c.course_name, course_count
FROM `wpt_subscription_course` sc
JOIN course c ON c.course_id = sc.course_id
JOIN
( SELECT COUNT(*) course_count, ca.wpt_users_id, ca.course_id,
min(ca.course_activity_entry_dt)
FROM wpt_user_subscriptions AS wus
JOIN course_activity AS ca ON ca.wpt_users_id = wus.wpt_users_id
WHERE wus.wpt_subscription_id = 35
AND ca.course_id = c.course_id
GROUP BY ca.wpt_users_id, ca.course_id
) sub1
WHERE sc.`wpt_subscription_id` = 35
I have This below query its working fine for Month Text in English but we need Month Text in Arabic How we do??I have Sql Server 2008R2.I have check using FORMAT function but its not work in 2008r2 edition.
DECLARE #tempdate TABLE
(
pricedate DATETIME NOT NULL,
priceid INT NOT NULL
)
INSERT INTO #tempdate
(pricedate,
priceid)
SELECT pricelist_date,
pricelist_id
FROM vw_lu_region_and_date_list
WHERE price_status = '3'
AND region_id = '1'
AND saletype = '2'
ORDER BY pricelist_date DESC;
WITH numbered
AS (SELECT *,
Row_number()
OVER (
partition BY Dateadd(month, Datediff(month, 0, pricedate), 0
)
ORDER BY pricedate DESC) AS rn
FROM #tempdate)
SELECT RIGHT(CONVERT(NVARCHAR(20), pricedate, 106), 8) AS PRICELIST_DATE,
priceid AS PRICELIST_ID
FROM numbered
WHERE rn = 1
ORDER BY priceid DESC
I have get result from above query like
Apr 2013
Mar 2013
but we need like Apr and Mar in Arabic????
I also suggest to store as normal date and you can probably convert in your client application rather than in SQL.
In the organization I once worked for the previous developer designed a SQL CLR function to convert dates into Hebrew dates and return in Hebrew.
But You Can Use This :
CREATE FUNCTION dbo.fnTranslateMonthNameToArabic
(#date as datetime)
RETURNS nvarchar(50)
AS
BEGIN
DECLARE #result AS nvarchar(50);
IF MONTH(#date) = 1
SET #result = (SELECT CONVERT(nvarchar(2), DAY(#date)) + N' ' + N'يناير' + N' ' + CONVERT(nvarchar(4), YEAR(#date)));
IF MONTH(#date) = 2
SET #result = N'and so on ...';
RETURN #result;
END
Go
-- Test
SELECT dbo.fnTranslateMonthNameToArabic({d N'2012-01-16'}) AS Arabic
At Last Please Take a Look at Arabic Language Support in SQL Server