여러분,
나는 비표준 조인 스크립트에서 꽤 오랜 시간 일해 왔으며 그렇게해야 할 필요가있는 것처럼 보입니다.
이 시점에서 두 테이블을 조인해야합니다.
첫 번째는 다른 도구에 대한 일련의 측정입니다. 측정은 세션에서 수행됩니다. 그러나 테이블에는 다음 항목 만 있습니다. 도구, 이벤트 시간, 결과 .
두 번째 테이블에는 세션에 대한 모든 정보가 있습니다.
도구, sessionid, starttime, endtime
그리고 나는 다음과 같은 측정의 분석을 할 필요가 있습니다. sessionid
기본적으로 나는 독특한 sessionid 첫 번째 표의 각 줄에
현재 내가하는 방식은 첫 번째 테이블의 각 행을 반복하고 두 번째 테이블에서 해당 행을 검색하는 것입니다. 수단 일치 함 이벤트 시간 사이에있다 시작 시간 과 끝내는 시간 이것을 사용 :
currentStartEndInfoindex=dt2 << Get Rows Where(:tool==thisTool & :measstart < thisEventtime & :measend > thisEventtime);
어디에 이 도구 과 thisEventtime 처음부터 반복되는 첫 번째 테이블의 도구와 시간입니다. 나는 독특한 목록으로 indeces를 얻는다. sessionid 두 번째 테이블에서이 조건과 일치하는 목록을 만든 다음 루프의 끝에서 첫 번째 테이블의 새 열을 채우는 데 사용되는 목록을 어셈블합니다. 이 "Get Rows Where"행은 스크립트 실행 시간의 85 %를 차지합니다.
이제 첫 번째 테이블에는 몇 백만 줄이 있고 두 번째 테이블에는 수십만 줄이 들어가면 8 시간에서 16 시간 사이에 다소 시간이 걸립니다.
나는 이것을 오래 실행할 여유가 없다.
따라서 질문 :
그것을 최적화 할 방법이 있습니까? Afterall은 첫 번째 테이블의 각 행에 대해 두 번째 테이블을 반복적으로 살펴 봅니다. 그리 효율적이지는 않습니다.
내가 가진 한 가지 아이디어는 도구로 두 번째 테이블을 하위 목록으로 나누고 특정 도구에 해당하는 하위 목록의 각 행에 대해 "행 행 얻기"를 수행하는 것입니다. 가장 좋은 방법을 구현하는 방법을 모릅니다.
어떤 도움이라도 대단히 감사하겠습니다.
감사!
여기에 첫 번째 근사치가 있습니다.
aaa = New Table( "aaa", // the "event" table
Add Rows( 6 ),
New Column( "tool", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [100, 100, 100, 200, 200, 200] ) ),
New Column( "eventtime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 21, 12, 31, 41, 42] ) ),
New Column( "result", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1, 1, 1, 0, 0] ) ),
New Column( "sessionID_added", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [., ., ., ., ., .] ) )
);
bbb = New Table( "bbb", // the start-end table
Add Rows( 4 ),
New Column( "tool", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [100, 100, 200, 200] ) ),
New Column( "sessionID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [111, 222, 333, 444] ) ),
New Column( "startTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [10, 20, 30, 40] ) ),
New Column( "endTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [19, 29, 39, 49] ) )
);
// build two lookup tables that find all the rows associated with a tool
aaaRowsFromTool = Associative Array();
For( irow = 1, irow <= N Rows( aaa ), irow++,
If( !(aaaRowsFromTool << Contains( aaa:tool[irow] )), //
aaaRowsFromTool[aaa:tool[irow]] = Eval List( {irow} )//
, //
Insert Into( aaaRowsFromTool[aaa:tool[irow]], irow ) //
)
);
bbbRowsFromTool = Associative Array();
For( irow = 1, irow <= N Rows( bbb ), irow++,
If( !(bbbRowsFromTool << Contains( bbb:tool[irow] )), //
bbbRowsFromTool[bbb:tool[irow]] = Eval List( {irow} )//
, //
Insert Into( bbbRowsFromTool[bbb:tool[irow]], irow ) //
)
);
toolList = bbbRowsFromTool << getkeys;
For( itool = 1, itool <= N Items( toolList ), itool += 1,
toolno = toolList[itool];
// build a sorted list of event times+row numbers for this tool
aaaRowList = aaaRowsFromTool[toolno];
aaa << selectrows( aaaRowList );
aaasub = aaa << Subset( Selected Rows( 1 ), Selected columns only( 0 ), link to original data table( 1 ) );
//aaasub << sort( by( eventTime ), replace table );
timeMatrix = aaasub:eventtime << getAsMatrix;
bbbRowList = bbbRowsFromTool[toolno];
For( irow = 1, irow <= N Items( bbbRowList ), irow += 1,
bbbRow = bbbRowList[irow];
start = bbb:startTime[bbbRow];
end = bbb:endTime[bbbRow];
id = bbb:sessionID[bbbRow];
// find the eventTimes between start and end, for this tool
//aaasub<<SELECTWHERE></SELECTWHERE>
그것은 작동하지만 너무 느립니다. eventTime을 사용하여 "이벤트"테이블을 정렬하고 loc ()를 바이너리 조회로 대체 할 수 있습니다.