国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

BI測試工具之跨數(shù)據(jù)庫數(shù)據(jù)對比,支持oracle,sqlserver

2024-08-29 13:54:22
字體:
供稿:網(wǎng)友
BI測試工具之跨數(shù)據(jù)庫數(shù)據(jù)對比,支持Oracle,sqlserver

應(yīng)用場景:

本周在進(jìn)行SIT,我?guī)椭鷥H有的一個(gè)測試妹妹對部分表進(jìn)行數(shù)據(jù)質(zhì)量驗(yàn)證,第一步需要做的就是比對source與stage表的table definition 與 數(shù)據(jù)內(nèi)容的一致性。

本項(xiàng)目使用的是oracle作為DW,source是oracle,sqlserver和xls.

沒有權(quán)限建立database link, 測試們常用的方法是比對總行數(shù),然后如果數(shù)據(jù)集太大的話,則抽樣比對,導(dǎo)出數(shù)據(jù)到xls,然后使用beyondcompare進(jìn)行比對。

如果值出現(xiàn)不同,則需要查找出哪些行的值不同,最少要找出一條具體的值。

我測試的時(shí)候發(fā)現(xiàn),手動去做這一些事也是挺費(fèi)力的。就寫了以下的小工具進(jìn)行輔助測試。

功能:

1.支持從oracle,sqlserver,xlsx中取數(shù)據(jù)進(jìn)行比對。

2.對oracle與sqlserver,可采用傳統(tǒng)的比對,各自獲取一個(gè)readonly ,forward 胡datareader,逐行比對。點(diǎn)擊CompareData按鈕。因?yàn)閿?shù)據(jù)庫不同找不到統(tǒng)一的方法計(jì)算值,oracle中的ora_hash和sqlserver中的hashbyte不一致。

3.對于oracle與oracle的或者是sqlserver對sqlserver的query比對,可以使用GetDiffRange按鈕,即二分查找法進(jìn)行比對。因?yàn)橄嗤臄?shù)據(jù)庫可以找到一個(gè)方法進(jìn)行數(shù)據(jù)比對。

測試數(shù)據(jù)如下:

在oracle的數(shù)據(jù)庫中執(zhí)行以下代碼,生成測試數(shù)據(jù)。

--create table mytest(id int, rid int,name varchar2(20));--create table mytest2(id int, rid int,name varchar2(20));declare i integer :=1;beginwhile i<110000 loopinsert into mytest(ID,RID,NAME) VALUES(mysequence.nextval,i,'dataitem'||i);i:=i+1;end loop;end ;   insert into mytest2 SELECT * FROM mytest order by id;   update mytest2 set rid=100 where id=100000; commit;select * from mytest minus select * from mytest2;   select count(*) as totalcount, to_char(avg(ora_hash(id||rid ||name))) as avghash from (select id as rn, t.* from mytest t)select count(*) as totalcount, to_char(avg(ora_hash(id||rid ||name))) as avghash from (select id as rn, t.* from mytest2 t)   update mytest2 set name='EvanTEst' where id=1000;commit;

Range:可以自己設(shè)定,如果是1的話,則直接定位到第一條不同的記錄,如果是大于1 則是一個(gè)區(qū)間值。

表示不同的數(shù)據(jù)行就是在他們之間。

為了同時(shí)支持oracle和sqlserver,我使用庫中自帶的接口IDbConnection和IDataReader進(jìn)行開發(fā),可以同時(shí)支持oracle和sqlserver and Xlsx.

sql要求:

二分查找需要樣本有序,所以需要寫成

select count(*) as totalcount, to_char(avg(ora_hash(id||rid ||name))) as avghash from (select id as rn, t.* from mytest t)

的樣式,第一個(gè)是總行數(shù),第二個(gè)要求是里面需要有一個(gè)固定列名叫rn。

我使用ora_hash函數(shù)對每行的值進(jìn)行hash,然后求平均值的方式來計(jì)算表區(qū)間內(nèi)行的內(nèi)容是否相同,這是oracle提供的函數(shù)。

類似的有函數(shù)checksum,但是計(jì)算速度要比這個(gè)慢許多,尤其是表數(shù)據(jù)量大的時(shí)候。

sqlserver中有hashbyte函數(shù)類似。 注意如果不使用to_char函數(shù),則算出的值會溢出,如果放到.net中來承接,會報(bào)oci數(shù)據(jù)溢出的錯(cuò)誤,所以to_char也是必須的。

歡迎大家分享BI測試的一些經(jīng)驗(yàn)心得。

軟件下載地址: files.cnblogs.com/huaxiaoyao/datacompare.rar

主要源碼:

 PRivate void compareData2(int start, int end,int total)        {            rtb_log.AppendText(string.Format("comparedata2({0},{1},{2})", start, end, total) + Environment.NewLine);            string tmpsql = " where rn between {0} and {1} ";            if (total == 0)            {                dr1 = getDataReader(conn, rtx_sql.Text);                dr2 = getDataReader(conn2, rtx_sql2.Text);            }            else            {                dr1 = getDataReader(conn, rtx_sql.Text + string.Format(tmpsql, start, end));                dr2 = getDataReader(conn2, rtx_sql2.Text + string.Format(tmpsql, start, end));            }            //assume the dr schema totalcount,avghash            bool isdiff = false;            while (dr1.Read() && dr2.Read())            {                if (total == 0) {end= total = dr1.GetInt32(0); }                for (int col = 1; col < dr1.FieldCount; col++)                {                    if (!dr1.GetValue(col).ToString().Equals(dr2.GetValue(col).ToString())                        ||                        !(dr1.IsDBNull(col) == dr2.IsDBNull(col))                        )                    {                        isdiff = true;                    }                }            }            dr1.Close();            dr2.Close();            //if isdiff=true the split the totalcount two part            if (isdiff)            {                if ((end - start < range)) return;                compareData2(start, (start + end) / 2, end);            }            else //if same            {                if (start == end) end = total;                compareData2(end, total, total);            }                  }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 霍山县| 资中县| 房山区| 安仁县| 临颍县| 佳木斯市| 定远县| 泸水县| 南平市| 乐安县| 盐源县| 都安| 松溪县| 文安县| 墨玉县| 施甸县| 临武县| 巩留县| 宽城| 靖江市| 侯马市| 蚌埠市| 贵州省| 额济纳旗| 大英县| 瑞丽市| 德安县| 通州区| 哈密市| 子长县| 潼关县| 桑日县| 丹东市| 长阳| 治县。| 尼勒克县| 通海县| 永年县| 通化市| 巴林左旗| 许昌市|