How to get XML element properties in SQL Server - sql-server

I am trying to parse XML data from a SSIS package, and I want to get the XML element property values.
<DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:refId="Package" DTS:CreationDate="9/15/2021 11:38:35 AM" DTS:CreationName="Microsoft.Package" DTS:CreatorComputerName="X" DTS:CreatorName="Y" DTS:DTSID="{5BDDA1D9-F546-47BC-81BB-E29C0E22D5DA}" DTS:ExecutableType="Microsoft.Package" DTS:LastModifiedProductVersion="16.0.694.0" DTS:LocaleID="1033" DTS:ObjectName="Mine" DTS:PackageType="5" DTS:VersionBuild="195" DTS:VersionGUID="{68B021E9-5664-4E2B-A64D-C8B5CAF38316}">
<DTS:Property DTS:Name="PackageFormatVersion">8</DTS:Property>
<DTS:ConnectionManagers>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[A]" DTS:CreationName="OLEDB" DTS:DTSID="{AE299D88-1DB8-48B1-8548-31BE5C2F2721}" DTS:ObjectName="A">
<DTS:PropertyExpression DTS:Name="InitialCatalog">#[User::A]</DTS:PropertyExpression>
<DTS:PropertyExpression DTS:Name="ServerName">#[User::B]</DTS:PropertyExpression>
<DTS:ObjectData>
<DTS:ConnectionManager DTS:Retain="True" DTS:ConnectRetryCount="1" DTS:ConnectRetryInterval="5" DTS:ConnectionString="Data Source=XXX;Initial Catalog=XXX;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Application Name=XXXXX;" />
</DTS:ObjectData>
</DTS:ConnectionManager>
</DTS:ConnectionManagers>
</DTS:Executable>
FOR THIS LINE:
<DTS:Property DTS:Name="PackageFormatVersion">8</DTS:Property>
I want to get the Name="PackageFormatVersion" from the Property element.
How do I do this in T-SQL?

Assuming that the XML is a value of a variable.
SQL
DECLARE #xml XML =
N'<DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:refId="Package" DTS:CreationDate="9/15/2021 11:38:35 AM" DTS:CreationName="Microsoft.Package" DTS:CreatorComputerName="X" DTS:CreatorName="Y" DTS:DTSID="{5BDDA1D9-F546-47BC-81BB-E29C0E22D5DA}"
DTS:ExecutableType="Microsoft.Package" DTS:LastModifiedProductVersion="16.0.694.0" DTS:LocaleID="1033" DTS:ObjectName="Mine" DTS:PackageType="5" DTS:VersionBuild="195" DTS:VersionGUID="{68B021E9-5664-4E2B-A64D-C8B5CAF38316}">
<DTS:Property DTS:Name="PackageFormatVersion">8</DTS:Property>
<DTS:ConnectionManagers>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[A]" DTS:CreationName="OLEDB" DTS:DTSID="{AE299D88-1DB8-48B1-8548-31BE5C2F2721}" DTS:ObjectName="A">
<DTS:PropertyExpression DTS:Name="InitialCatalog">#[User::A]</DTS:PropertyExpression>
<DTS:PropertyExpression DTS:Name="ServerName">#[User::B]</DTS:PropertyExpression>
<DTS:ObjectData>
<DTS:ConnectionManager DTS:Retain="True" DTS:ConnectRetryCount="1" DTS:ConnectRetryInterval="5"
DTS:ConnectionString="Data Source=XXX;Initial Catalog=XXX;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Application Name=XXXXX;"/>
</DTS:ObjectData>
</DTS:ConnectionManager>
</DTS:ConnectionManagers>
</DTS:Executable>';
;WITH XMLNAMESPACES(DEFAULT 'www.microsoft.com/SqlServer/Dts')
SELECT result = #xml.value('(/Executable/Property/text())[1]', 'INT');
Output
result
8

The ask is for the attribute value. And the catch is that the default namespace doesn't apply to attributes, so you have to add it explicitly.
DECLARE #xml XML =
N'<DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:refId="Package" DTS:CreationDate="9/15/2021 11:38:35 AM" DTS:CreationName="Microsoft.Package" DTS:CreatorComputerName="X" DTS:CreatorName="Y" DTS:DTSID="{5BDDA1D9-F546-47BC-81BB-E29C0E22D5DA}"
DTS:ExecutableType="Microsoft.Package" DTS:LastModifiedProductVersion="16.0.694.0" DTS:LocaleID="1033" DTS:ObjectName="Mine" DTS:PackageType="5" DTS:VersionBuild="195" DTS:VersionGUID="{68B021E9-5664-4E2B-A64D-C8B5CAF38316}">
<DTS:Property DTS:Name="PackageFormatVersion">8</DTS:Property>
<DTS:ConnectionManagers>
<DTS:ConnectionManager DTS:refId="Package.ConnectionManagers[A]" DTS:CreationName="OLEDB" DTS:DTSID="{AE299D88-1DB8-48B1-8548-31BE5C2F2721}" DTS:ObjectName="A">
<DTS:PropertyExpression DTS:Name="InitialCatalog">#[User::A]</DTS:PropertyExpression>
<DTS:PropertyExpression DTS:Name="ServerName">#[User::B]</DTS:PropertyExpression>
<DTS:ObjectData>
<DTS:ConnectionManager DTS:Retain="True" DTS:ConnectRetryCount="1" DTS:ConnectRetryInterval="5"
DTS:ConnectionString="Data Source=XXX;Initial Catalog=XXX;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Application Name=XXXXX;"/>
</DTS:ObjectData>
</DTS:ConnectionManager>
</DTS:ConnectionManagers>
</DTS:Executable>';
;WITH XMLNAMESPACES(DEFAULT 'www.microsoft.com/SqlServer/Dts', 'www.microsoft.com/SqlServer/Dts' as DTS)
SELECT result = #xml.value('(/Executable/Property/#DTS:Name)[1]', 'varchar(200)');

Related

datomic / datalevin performance and db size - is this schema wrong?

I am trying to enter what's essentially tabular data in a datalevin dB. I'm wondering whether I'm doing something deeply wrong, maybe with the schema? The database grows extremely fast on disk (100x bigger than the equivalent CSV) and query time is also quite slow, and increasing with the size of the dB.
Each transaction below ("fake-portfolio") is around 900k datoms, it takes several seconds to write, and after about 10 transactions on my machine it just crashes.
The typical query I'd like to do is something akin to
(d/q '[:find ?date ?portfolio (sum ?nav)
:in $
:keys date portfolio nav
:with ?position/bond
:where
[?e :position/portfolio ?portfolio]
[?e :position/date ?date]
[?e :position/bond-id-ref ?bond]
[?e :position/weight ?nav]
]
(d/db test-connection)
(def test-schema {
:position/bond-id-ref {:db/valueType :db.type/long :db/cardinality :db.cardinality/one} ;will link to bond above
:position/date {:db/valueType :db.type/long :db/cardinality :db.cardinality/one}
:position/portfolio {:db/valueType :db.type/string :db/cardinality :db.cardinality/one}
:position/weight {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/bm-weight {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/weight-delta {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/contrib-yield {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/contrib-zspread {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/contrib-gspread {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/contrib-mdur {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/mdur-delta {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/bm-contrib-eir-duration {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/bm-contrib-yield {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/bm-contrib-govt-spread {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/contrib-beta-1y-daily {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/duration-times-spread-weight {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/quant-value-4d {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}
:position/quant-value-2d {:db/valueType :db.type/double :db/cardinality :db.cardinality/one}})
(def test-database-path "/tmp/datalevin/testpositions")
(defn fake-portfolio [d]
(into []
(for [p (range 0 25)
b (range 0 2000)]
{
:position/bond-id-ref b
:position/date d
:position/portfolio (str "portfolio-" p)
:position/weight 0.5
:position/bm-weight 0.2
:position/weight-delta 0.3
:position/contrib-yield 0.8
:position/contrib-zspread 3.4
:position/contrib-gspread 6.7
:position/contrib-mdur 8.756
:position/mdur-delta 45.6568
:position/bm-contrib-eir-duration 0.3
:position/bm-contrib-yield 0.0
:position/bm-contrib-govt-spread 78.5
:position/contrib-beta-1y-daily 45.5
:position/duration-times-spread-weight 0.3
:position/quant-value-4d 0.2
:position/quant-value-2d 0.7}
)
)
)
(def test-connection (d/get-conn test-database-path test-schema))
(defn fill-test-db [n]
(doseq [i (range n)]
(d/transact! test-connection (fake-portfolio i))))
Thank you,

Solr Repeater ReplicationHandler Exception

I am using Solr8.8.0 leader and there are about 16 repeaters. I am seeing following exception on repeater. (Not using SolrCloud) When I checked the Leader instance for file "_9.fdm", it is not there. So my question is where the repeater is getting the name of file from when it does not even exist on Leader? And how to resolve the issue. TIA
Exception while writing response for params: generation=11&checksum=true&qt=/replication&file=_9.fdm&wt=filestream&command=filecontent
java.nio.file.NoSuchFileException: /app/solr/testCore/data/index.20210817190431551/_9.fdm
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:177)
at java.nio.channels.FileChannel.open(FileChannel.java:287)
at java.nio.c`enter code here`hannels.FileChannel.open(FileChannel.java:335)
at org.apache.lucene.store.MMapDirectory.openInput(MMapDirectory.java:238)
at org.apache.lucene.store.NRTCachingDirectory.openInput(NRTCachingDirectory.java:181)
at org.apache.solr.handler.ReplicationHandler$DirectoryFileStream.write(ReplicationHandler.java:1648)
at org.apache.solr.core.SolrCore$4.write(SolrCore.java:2796)
at org.apache.solr.response.QueryResponseWriterUtil.writeQueryResponse(QueryResponseWriterUtil.java:49)
at org.apache.solr.servlet.HttpSolrCall.writeResponse(HttpSolrCall.java:890)
at org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:583)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:427)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:357)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:201)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1612)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1582)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:191)
at org.eclipse.jetty.server.handler.InetAccessHandler.handle(InetAccessHandler.java:177)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:516)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:773)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:905)
at java.lang.Thread.run(Thread.java:748)

read Xml into ms sql

I want to read the xml pasted below into sql. I tried several ways from the web to parse this xml without success.
I tried the following script:
CREATE TABLE [dbo].[Ejemplo2](
[RutEmisor][nvarchar](12) null,
[RutEnvia][nvarchar](12) null,
[RutReceptor][nvarchar](12) null,
[FchResol][nvarchar](12) null,
[NroResol][nvarchar](12) null
)
GO
DECLARE #messagebody XML
SELECT #messagebody = BulkColumn
FROM OPENROWSET(BULK 'C:\Ejemplo.xml', SINGLE_CLOB) AS X
INSERT INTO [dbo].[Ejemplo2]
select a.value(N'(./RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/EnvioDTE/SetDTE/Caratula') as r(a);
Select * from dbo.Ejemplo2
But I get 0 rows
I tried with more simple examples and always return the data, but in this case I can't figure whats is wrong.
Any help on this will be appreciated.
The xml follows
<?xml version="1.0" encoding="ISO-8859-1"?>
<EnvioDTE xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd" version="1.0">
<SetDTE ID="SetDoc">
<TmstFirmaEnv>2003-10-13T09:33:22</TmstFirmaEnv>
<Caratula version="1.0">
<RutEmisor>97975000-5</RutEmisor>
<RutEnvia>7880442-4</RutEnvia>
<RutReceptor>60803000-K</RutReceptor>
<FchResol>2003-09-02</FchResol>
<NroResol>0</NroResol>
<SubTotDTE>
<TpoDTE>33</TpoDTE>
<NroDTE>1</NroDTE>
</SubTotDTE>
</Caratula>
<DTE version="1.0">
<Documento ID="F60T33">
<Encabezado>
<IdDoc>
<TipoDTE>33</TipoDTE>
<Folio>60</Folio>
<FchEmis>2003-10-13</FchEmis>
</IdDoc>
<Emisor>
<RUTEmisor>97975000-5</RUTEmisor>
<RznSoc>RUT DE PRUEBA</RznSoc>
<GiroEmis>Insumos de Computacion</GiroEmis>
<Acteco>31341</Acteco>
<CdgSIISucur>1234</CdgSIISucur>
<DirOrigen>Teatinos 120, Piso 4</DirOrigen>
<CmnaOrigen>Santiago</CmnaOrigen>
<CiudadOrigen>Santiago</CiudadOrigen>
</Emisor>
<Receptor>
<RUTRecep>77777777-7</RUTRecep>
<RznSocRecep>EMPRESA LTDA</RznSocRecep>
<GiroRecep>COMPUTACION</GiroRecep>
<DirRecep>SAN DIEGO 2222</DirRecep>
<CmnaRecep>LA FLORIDA</CmnaRecep>
<CiudadRecep>SANTIAGO</CiudadRecep>
</Receptor>
<Totales>
<MntNeto>100000</MntNeto>
<TasaIVA>19</TasaIVA>
<IVA>19000</IVA>
<MntTotal>119000</MntTotal>
</Totales>
</Encabezado>
<Detalle>
<NroLinDet>1</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>011</VlrCodigo>
</CdgItem>
<NmbItem>Parlantes Multimedia 180W.</NmbItem>
<DscItem/>
<QtyItem>20</QtyItem>
<PrcItem>4500</PrcItem>
<MontoItem>90000</MontoItem>
</Detalle>
<Detalle>
<NroLinDet>2</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>0231</VlrCodigo>
</CdgItem>
<NmbItem>Mouse Inalambrico PS/2</NmbItem>
<DscItem/>
<QtyItem>1</QtyItem>
<PrcItem>5000</PrcItem>
<MontoItem>5000</MontoItem>
</Detalle>
<Detalle>
<NroLinDet>3</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>1515</VlrCodigo>
</CdgItem>
<NmbItem>Caja de Diskettes 10 Unidades</NmbItem>
<DscItem/>
<QtyItem>5</QtyItem>
<PrcItem>1000</PrcItem>
<MontoItem>5000</MontoItem>
</Detalle>
<TED version="1.0">
<DD>
<RE>97975000-5</RE>
<TD>33</TD>
<F>60</F>
<FE>2003-10-13</FE>
<RR>77777777-7</RR>
<RSR>EMPRESA LTDA</RSR>
<MNT>119000</MNT>
<IT1>Parlantes Multimedia 180W.</IT1>
<CAF version="1.0">
<DA>
<RE>97975000-5</RE>
<RS>RUT DE PRUEBA</RS>
<TD>33</TD>
<RNG>
<D>1</D>
<H>200</H>
</RNG>
<FA>2003-09-04</FA>
<RSAPK>
<M>0a4O6Kbx8Qj3K4iWSP4w7KneZYeJ+g/prihYtIEolKt3cykSxl1zO8vSXu397QhTmsX7SBEudTUx++2zDXBhZw==</M>
<E>Aw==</E>
</RSAPK>
<IDK>100</IDK>
</DA>
<FRMA algoritmo="SHA1withRSA">g1AQX0sy8NJugX52k2hTJEZAE9Cuul6pqYBdFxj1N17umW7zG/hAavCALKByHzdYAfZ3LhGTXCai5zNxOo4lDQ==</FRMA>
</CAF>
<TSTED>2003-10-13T09:33:20</TSTED>
</DD>
<FRMT algoritmo="SHA1withRSA">GbmDcS9e/jVC2LsLIe1iRV12Bf6lxsILtbQiCkh6mbjckFCJ7fj/kakFTS06Jo8i
S4HXvJj3oYZuey53Krniew==</FRMT>
</TED>
<TmstFirma>2003-10-13T09:33:20</TmstFirma>
</Documento>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#F60T33">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>hlmQtu/AyjUjTDhM3852wvRCr8w=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>JG1Ig0pvSIH85kIKGRZUjkyX6CNaY08Y94j4UegTgDe8+wl61GzqjdR1rfOK9BGn93AMOo6aiAgolW0k/XklNVtM/ZzpNNS3d/fYVa1q509mAMSXbelxSM3bjoa7H6Wzd/mV1PpQ8zK5gw7mgMMP4IKxHyS92G81GEguSmzcQmA=</SignatureValue>
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>
tNEknkb1kHiD1OOAWlLKkcH/UP5UGa6V6MYso++JB+vYMg2OXFROAF7G8BNFFPQx
iuS/7y1azZljN2xq+bW3bAou1bW2ij7fxSXWTJYFZMAyndbLyGHM1e3nVmwpgEpx
BHhZzPvwLb55st1wceuKjs2Ontb13J33sUb7bbJMWh0=
</Modulus>
<Exponent>
AQAB
</Exponent>
</RSAKeyValue>
</KeyValue>
<X509Data>
<X509Certificate>MIIEgjCCA+ugAwIBAgIEAQAApzANBgkqhkiG9w0BAQUFADCBtTELMAkGA1UEBhMC
Q0wxHTAbBgNVBAgUFFJlZ2lvbiBNZXRyb3BvbGl0YW5hMREwDwYDVQQHFAhTYW50
aWFnbzEUMBIGA1UEChQLRS1DRVJUQ0hJTEUxIDAeBgNVBAsUF0F1dG9yaWRhZCBD
ZXJ0aWZpY2Fkb3JhMRcwFQYDVQQDFA5FLUNFU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GFyYSB1
c28gdHJpYnV0YXJpbywgcGFnb3MsIGNvbWVyY2lvIHkgb3Ryb3MwCwYDVR0PBAQD
AgTwMA0GCSqGSIb3DQEBBQUAA4GBABMfCyJF0mNXcov8iEWvjGFyyPTsXwvsYbbk
OJ41wjaGOFMCInb4WY0ngM8BsDV22bGMs8oLyX7rVy16bGA8Z7WDUtYhoOM7mqXw
/Hrpqjh3JgAf8zqdzBdH/q6mAbdvq/yb04JHKWPC7fMFuBoeyVWAnhmuMZfReWQi
MUEHGGIW</X509Certificate>
</X509Data>
</KeyInfo>
</Signature></DTE>
</SetDTE><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#SetDoc">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>4OTWXyRl5fw3htjTyZXQtYEsC3E=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>sBnr8Yq14vVAcrN/pKLD/BrqUFczKMW3y1t3JOrdsxhhq6IxvS13SgyMXbIN/T9ciRaFgNabs3pi732XhcpeiSmD1ktzbRctEbSIszYkFJY49k0eB+TVzq3eVaQr4INrymfuOnWj78BZcwKuXvDy4iAcx6/TBbAAkPFwMP9ql2s=</SignatureValue>
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>
tNEknkb1kHiD1OOAWlLKkcH/UP5UGa6V6MYso++JB+vYMg2OXFROAF7G8BNFFPQx
iuS/7y1azZljN2xq+bW3bAou1bW2ij7fxSXWTJYFZMAyndbLyGHM1e3nVmwpgEpx
BHhZzPvwLb55st1wceuKjs2Ontb13J33sUb7bbJMWh0=
</Modulus>
<Exponent>
AQAB
</Exponent>
</RSAKeyValue>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DAWgBTg
KP3S4GBPs0brGsz1CJEHcjodCDCB0AYDVR0gBIHIMIHFMIHCBggrBgEEAcNSBTCB
tTAvBggrBgEFBQcCARYjaHR0cDovL3d3dy5lLWNlcnRjaGlsZS5jbC8yMDAwL0NQ
Uy8wgYEGCCsGAQUFBwICMHUac0VsIHRpdHVsYXIgaGEgc2lkbyB2YWxpZG8gZW4g
Zm9ybWEgcHJlc2VuY2lhbCwgcXVlZGFuZG8gZWwgQ2VydGlmaWNhZG8gcGFyYSB1
c28gdHJpYnV0YXJpbywgcGFnb3MsIGNvbWVyY2lvIHkgb3Ryb3MwCwYDVR0PBAQD
AgTwMA0GCSqGSIb3DQEBBQUAA4GBABMfCyJF0mNXcov8iEWvjGFyyPTsXwvsYbbk
OJ41wjaGOFMCInb4WY0ngM8BsDV22bGMs8oLyX7rVy16bGA8Z7WDUtYhoOM7mqXw
/Hrpqjh3JgAf8zqdzBdH/q6mAbdvq/yb04JHKWPC7fMFuBoeyVWAnhmuMZfReWQi
MUEHGGIW</X509Certificate>
</X509Data>
</KeyInfo>
</Signature></EnvioDTE>
This Works. You add "*:" for the nodes.
DECLARE #messagebody XML
SELECT #messagebody = BulkColumn
FROM OPENROWSET(BULK 'C:\Ejemplo.xml', SINGLE_CLOB) AS X
PRINT CONVERT(VARCHAR(MAX),#messagebody)
INSERT INTO [dbo].[Ejemplo24]
select a.value(N'(./*:RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./*:RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./*:RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./*:FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./*:NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/*:EnvioDTE/*:SetDTE/*:Caratula') as r(a);
Your query is great, but you must specify the default namespace xmlns
Try like this:
WITH XMLNAMESPACES(DEFAULT 'http://www.sii.cl/SiiDte')
INSERT INTO [dbo].[Ejemplo2]
select a.value(N'(./RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/EnvioDTE/SetDTE/Caratula') as r(a);

Updating value with cardinality many

I have a schema like this:
[{:db/id #db/id[:db.part/db]
:db/ident :person/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A person's name"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :person/roles
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/many
:db/doc "A person's role"
:db.install/_attribute :db.part/db}]
And a code like this:
;; insert new person
(def new-id (-> (d/transact conn [{:db/id (d/tempid :db.part/user)
:person/name "foo"
:person/roles #{:admin}}])
(:tempids)
(vals)
(first)))
(defn get-roles
[db eid]
(d/q '[:find ?roles .
:in $ ?eid
:where [?eid :user/roles ?roles]]))
(get-roles (d/db conn) new-id) ;; => [:admin]
;; update a person
(d/transact conn [{:db/id new-id
:person/roles #{:client}}])
(get-roles (d/db conn) new-id) ;; => [:admin :client]
It seems the default behaviour on it is, it will just assoc the new value.
How can I get this result, after doing the updating transaction:
(get-roles (d/db conn) new-id) ;; => [:client]
if what you want is to "reset" the list of roles to a new value (an 'absolute' operation 'in contrast to the 'relative' operations of just adding or removing roles), you'll have to use a transaction function to perform a diff and retract the values that need be.
Here's a basic generic implementation:
{:db/id (d/tempid :db.part/user),
:db/ident :my.fns/reset-to-many,
:db/fn
(d/function
{:lang :clojure,
:requires '[[datomic.api :as d]],
:params '[db e attr new-vals],
:code
'(let [ent (or (d/entity db e)
(throw (ex-info "Entity not found"
{:e e :t (d/basis-t db)})))
entid (:db/id ent)
old-vals (get ent attr)]
(into
[{:db/id (:db/id ent)
;; adding the new values
attr new-vals}]
;; retracting the old values
(comp
(remove (set new-vals))
(map (fn [v]
[:db/retract entid attr v])))
old-vals)
)})}
;; Usage
(d/transact conn [[:my.fns/reset-to-many new-id :person/roles #{:client}]])
Here is a solution once suggested from Robert Stuttaford
(defn many-delta-tx
"Produces the transaction necessary to have
`new` be the value for `entity-id` at `attr`
`new` is expected to be a set."
[db entity-id attr new]
(let [current (into #{} (map :v)
(d/datoms db :eavt
entity-id
(d/entid db attr)))]
(concat (for [id (clojure.set/difference new current)]
[:db/add entity-id attr id])
(for [id (clojure.set/difference current new)]
[:db/retract entity-id attr id]))))
For ease of testing, I would like to slightly modify part of the example of original question.
Change of the schema. I add db/unique
[{:db/id #db/id[:db.part/db]
:db/ident :person/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db/doc "A person's name"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :person/roles
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/many
:db/doc "A person's role"
:db.install/_attribute :db.part/db}]
get-roles
(defn get-roles
[db eid]
(d/q '[:find [?roles ...]
:in $ ?eid
:where [?eid :person/roles ?roles]] db eid))
My testing example
;; (many-delta-tx (d/db conn) [:person/name "foo"] :person/roles #{:sales :client})
;; => ([:db/add [:person/name "foo"] :person/roles :sales] [:db/retract [:person/name "foo"] :person/roles :admin]))

EarlyTerminatingCollectorException in MLT Component of SOLR 4.4

I send a query to SOLR, which returns exactly one document. It's a "id:some_doc_id" search. Here are the parameters as shown in the response:
params: {
mlt.mindf: "1",
mlt.count: "5",
mlt.fl: "text",
fl: "id,,application_id,... project_start,project_end,project_title,score",
start: "0",
q: "id:some_doc_id",
mlt.mintf: "1",
mlt: "true",
wt: "json",
rows: "1"
}
The reponse key contains the document I expected, but I also get an error, which seems to happen in the MLT component. Here's the stack trace provided in the response:
org.apache.solr.search.EarlyTerminatingCollectorException
at org.apache.solr.search.EarlyTerminatingCollector.collect(EarlyTerminatingCollector.java:62)
at org.apache.lucene.search.BooleanScorer2.score(BooleanScorer2.java:289)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:624)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:297)
at org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1494)
at org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1363)
at org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:474)
at org.apache.solr.search.SolrIndexSearcher.getDocList(SolrIndexSearcher.java:1226)
at org.apache.solr.handler.MoreLikeThisHandler$MoreLikeThisHelper.getMoreLikeThis(MoreLikeThisHandler.java:365)
at org.apache.solr.handler.component.MoreLikeThisComponent.getMoreLikeThese(MoreLikeThisComponent.java:356)
at org.apache.solr.handler.component.MoreLikeThisComponent.process(MoreLikeThisComponent.java:113)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:208)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1904)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:659)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:362)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:158)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:724org.apache.solr.search.EarlyTerminatingCollectorException
at org.apache.solr.search.EarlyTerminatingCollector.collect(EarlyTerminatingCollector.java:62)
at org.apache.lucene.search.BooleanScorer2.score(BooleanScorer2.java:289)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:624)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:297)
at org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1494)
at org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1363)
at org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:474)
at org.apache.solr.search.SolrIndexSearcher.getDocList(SolrIndexSearcher.java:1226)
at org.apache.solr.handler.MoreLikeThisHandler$MoreLikeThisHelper.getMoreLikeThis(MoreLikeThisHandler.java:365)
at org.apache.solr.handler.component.MoreLikeThisComponent.getMoreLikeThese(MoreLikeThisComponent.java:356)
at org.apache.solr.handler.component.MoreLikeThisComponent.process(MoreLikeThisComponent.java:113)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:208)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1904)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:659)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:362)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:158)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:724))
My code worked fine before the update to SOLR 4.4. Any hint what's going on and how to solve it?
Thrown by EarlyTerminatingCollector when the maximum to abort the scoring / collection process early, when the specified maximum number of documents were collected.
This description doesn't sound like a real exception and more like a way to abort the collecting of documents.
#Override
public void collect(int doc) throws IOException {
delegate.collect(doc);
lastDocId = doc;
numCollected++;
if(numCollected==maxDocsToCollect) {
throw new EarlyTerminatingCollectorException(numCollected, lastDocId);
}
}

Resources