2017-11-01 2 views
0

서로 x 초 이상 걸리는 토큰 쌍을 찾으려고합니다.여러 개의 큰 XML 파일을 구문 분석합니다. 일치하는 토큰이 x 초 이상 떨어진 경우 출력합니다.

XML 데이터는 다음과 같습니다

<entry stamp="2017-10-30T19:19:59" level="MESSAGE" location="Process" message="token is 191"/> 
<entry stamp="2017-10-30T19:20:59" level="MESSAGE" location="Process" message="token is 192"/> 
<entry stamp="2017-10-30T19:21:59" level="MESSAGE" location="Process" message="token is 193"/> 
<entry stamp="2017-10-30T19:22:59" level="MESSAGE" location="Process" message="token is 194"/> 
<entry stamp="2017-10-30T19:23:59" level="MESSAGE" location="Process" message="token is 191"/> 
<entry stamp="2017-10-30T19:24:59" level="MESSAGE" location="Process" message="token is 192"/> 
<entry stamp="2017-10-30T19:25:59" level="MESSAGE" location="Process" message="token is 193"/> 
<entry stamp="2017-10-30T19:25:59" level="MESSAGE" location="Process" message="token is 194"/> 

실제 메시지는 매우 깁니다. 그것은 각각에 토큰이 있습니다.

고유 한 IN 토큰이있는 행이 있으며 해당 OUT 토큰이 있습니다.

일반적으로 IN 및 OUT 토큰은 서로 1 초 내에 발생합니다.

이 파일은 거대 - 100MB이며 수백 개가 있습니다.

x 초 이상 떨어져있는 이상치 만 존재합니다.

해당 줄이 있으면 파일에 추가하십시오.

의견이 있으십니까? xmlstarlet을 사용하고 있지만, 아이디어를 파악하고 RHEL에서 실행할 수 있다면 본질적으로 어떤 것도 작동 할 수 있습니다.

+0

_ "고유 한 IN 토큰이 있고 해당 OUT 토큰이 있습니다."_ _ 표시 한 XML과 어떻게 관련이 있습니까? 도움이 필요하면 모든 관련 정보와 데이터를 보여줘야합니다. –

+0

주어진 '@ message'가있는 첫 번째 ''요소가 IN 토큰으로 해석되고 동일한 '@ message'를 갖는 두 번째 ''요소가 해당 OUT 토큰으로 해석된다고 추측합니다. 그러나 나는 완전히 틀릴 수도 있습니다. 분명히 설명이 명확하지 않습니다. –

+0

RHEL = Red Hat Enterprise Linux를 찾지 않고 다른 사람을 저장하려면. –

답변

1

다음은 XSLT 3.0에서 스트리밍을 사용하는 솔루션입니다.

<xsl:mode streamable="yes"/> 
<xsl:template match="/*"> 
    <xsl:iterate select="entry"> 
    <xsl:param name="unmatched" select="map{}"/> 
    <!-- the param contains a map from @message to @stamp --> 
    <xsl:variable name="token" select="string(@message)"/> 
    <xsl:variable name="time" select="xs:dateTime(@stamp)"/> 
    <xsl:choose> 
     <xsl:when test="map:contains($unmatched, $token)"> 
     <xsl:if test="$time - map:get($unmatched, $token) 
         gt xs:dayTimeDuration('PT1S')"> 
      <outlier>{$token}</outlier> 
     </xsl:if> 
     <xsl:next-iteration> 
      <xsl:with-param name="unmatched" 
          select="map:remove($unmatched, $token)"/> 
     </xsl:next-iteration> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:next-iteration> 
      <xsl:with-param name="unmatched" 
          select="map:put($unmatched, $token, $time)"/> 
     </xsl:next-iteration> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:iterate> 
</xsl:template> 

은 어떻게 작동 : 변수 $unmatched에 바인딩지도에서 현재의 상태를 유지, 항목 요소를 통해 스트리밍 반복을 수행합니다. 어느 시점에서나 변수는 IN 이벤트가 발생했지만 OUT 이벤트가 발생하지 않은 토큰을 보유합니다. 특정 항목을 처리 할 때 먼저이 맵에 토큰이 있는지 여부에 따라 IN 또는 OUT 이벤트인지 여부를 결정하십시오. OUT 이벤트 인 경우 타임 스탬프를 IN 이벤트와 비교하고 나중에 두 초 이상이되면 아웃 라이어로보고합니다. 두 경우 모두지도에서 토큰을 삭제하십시오. IN 이벤트 인 경우 토큰을 맵에 추가 한 후 계속하십시오.

실제로 스트리밍없이 100MB를 처리 할 수 ​​있어야하므로 무료 Saxon-HE 제품에서 스트리밍을 끄고 시도해 볼 수 있습니다. 500Mb를 초과 할 때만 스트리밍을 활성화해야합니다.

관련 문제