From sudheshnaiyer at yahoo.com Sun Nov 1 11:51:18 2015 From: sudheshnaiyer at yahoo.com (sudheshna iyer) Date: Sun, 1 Nov 2015 19:51:18 +0000 (UTC) Subject: [xquery-talk] Xquery : Sort and get only the first record References: <1560802792.538837.1446407478210.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1560802792.538837.1446407478210.JavaMail.yahoo@mail.yahoo.com> Team, I have an xml which has multiple jobs elements. I want to sort the jobs and want to output only the latest job. Note that can be empty indicating that it is the current job. Basically I want to order by jobs/job/EndDate in descending fashion and select only the first record.. How do I do that using xquery? Input request: ?? ?????qq ?????qq ?? ?? ????? ???????? ???????????123 ???????????aaa bbb ??????????? ?????????????? ?????????????????Analyst ?????????????????1 ?????????????????01-01-2015 ?????????????????08-30-2015 ?????????????? ?????????????? ?????????????????Programmer ?????????????????2 ?????????????????08-31-2015 ????????????????? ?????????????? ??????????? ???????? ????? ?? Expected output: ?? ?????qq ?????qq ?? ?? ????? ???????? ???????????123 ???????????aaa bbb ??????????? ?????????????? ?????????????????Programmer ?????????????????2 ?????????????????08-31-2015 ????????????????? ?????????????? ??????????? ???????? ????? ?? Your help is greatly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From christian.gruen at gmail.com Sun Nov 1 13:26:32 2015 From: christian.gruen at gmail.com (=?UTF-8?Q?Christian_Gr=C3=BCn?=) Date: Sun, 1 Nov 2015 22:26:32 +0100 Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: <1560802792.538837.1446407478210.JavaMail.yahoo@mail.yahoo.com> References: <1560802792.538837.1446407478210.JavaMail.yahoo@mail.yahoo.com> <1560802792.538837.1446407478210.JavaMail.yahoo@mail.yahoo.com> Message-ID: If your XQuery processor supports XQuery Update, this would be one solution: copy $xml := doc('x.xml') modify ( delete node subsequence( for $job in $xml//job order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ) descending return $job , 2) ) return $xml Best, Christian On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer wrote: > Team, > > I have an xml which has multiple jobs elements. I want to sort the jobs and > want to output only the latest job. Note that can be empty > indicating that it is the current job. > > Basically I want to order by jobs/job/EndDate in descending fashion and > select only the first record.. > > How do I do that using xquery? > > Input request: > > > > qq > qq > > > > > 123 > aaa bbb > > > Analyst > 1 > 01-01-2015 > 08-30-2015 > > > Programmer > 2 > 08-31-2015 > > > > > > > > > Expected output: > > > > > qq > qq > > > > > 123 > aaa bbb > > > Programmer > 2 > 08-31-2015 > > > > > > > > > Your help is greatly appreciated. > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From sudheshnaiyer at yahoo.com Mon Nov 2 05:53:49 2015 From: sudheshnaiyer at yahoo.com (sudheshna iyer) Date: Mon, 2 Nov 2015 13:53:49 +0000 (UTC) Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: References: Message-ID: <357302902.855057.1446472430000.JavaMail.yahoo@mail.yahoo.com> Thank you very much, Christian. Let me try this.. From: Christian Gr?n To: sudheshna iyer Cc: "talk at x-query.com" Sent: Sunday, November 1, 2015 4:26 PM Subject: Re: [xquery-talk] Xquery : Sort and get only the first record If your XQuery processor supports XQuery Update, this would be one solution: ? copy $xml := doc('x.xml') ? modify ( ? ? delete node subsequence( ? ? ? for $job in $xml//job ? ? ? order by xs:date(replace($job/StartDate, ? ? ? ? "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ? ? ? ) descending ? ? ? return $job ? ? , 2) ? ) ? return $xml Best, Christian On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer wrote: > Team, > > I have an xml which has multiple jobs elements. I want to sort the jobs and > want to output only the latest job. Note that can be empty > indicating that it is the current job. > > Basically I want to order by jobs/job/EndDate in descending fashion and > select only the first record.. > > How do I do that using xquery? > > Input request: > > >? >? ? ? qq >? ? ? qq >? >? >? ? ? >? ? ? ? >? ? ? ? ? ? 123 >? ? ? ? ? ? aaa bbb >? ? ? ? ? ? >? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? Analyst >? ? ? ? ? ? ? ? ? 1 >? ? ? ? ? ? ? ? ? 01-01-2015 >? ? ? ? ? ? ? ? ? 08-30-2015 >? ? ? ? ? ? ? >? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? Programmer >? ? ? ? ? ? ? ? ? 2 >? ? ? ? ? ? ? ? ? 08-31-2015 >? ? ? ? ? ? ? ? ? >? ? ? ? ? ? ? >? ? ? ? ? ? >? ? ? ? >? ? ? >? > > > Expected output: > > > >? >? ? ? qq >? ? ? qq >? >? >? ? ? >? ? ? ? >? ? ? ? ? ? 123 >? ? ? ? ? ? aaa bbb >? ? ? ? ? ? >? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? Programmer >? ? ? ? ? ? ? ? ? 2 >? ? ? ? ? ? ? ? ? 08-31-2015 >? ? ? ? ? ? ? ? ? >? ? ? ? ? ? ? >? ? ? ? ? ? >? ? ? ? >? ? ? >? > > > Your help is greatly appreciated. > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpbourret at rpbourret.com Mon Nov 2 09:27:46 2015 From: rpbourret at rpbourret.com (Ronald Bourret) Date: Mon, 2 Nov 2015 09:27:46 -0800 Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: <357302902.855057.1446472430000.JavaMail.yahoo@mail.yahoo.com> References: <357302902.855057.1446472430000.JavaMail.yahoo@mail.yahoo.com> Message-ID: <56379D12.2000702@rpbourret.com> Can't use just use a predicate that returns the first element in the sorted sequence? Something like: let $seq = for $job in doc('x.xml')//job order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ) descending return $job return $seq[1] (My apologies if the syntax isn't exact. I haven't written an XQuery for quite a while.) -- Ron On 11/2/2015 5:53 AM, sudheshna iyer wrote: > Thank you very much, Christian. Let me try this.. > > > > ------------------------------------------------------------------------ > *From:* Christian Gr?n > *To:* sudheshna iyer > *Cc:* "talk at x-query.com" > *Sent:* Sunday, November 1, 2015 4:26 PM > *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record > > If your XQuery processor supports XQuery Update, this would be one solution: > > copy $xml := doc('x.xml') > modify ( > delete node subsequence( > for $job in $xml//job > order by xs:date(replace($job/StartDate, > "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") > ) descending > return $job > , 2) > ) > return $xml > > Best, > Christian > > > > > On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > wrote: > > Team, > > > > I have an xml which has multiple jobs elements. I want to sort the > jobs and > > want to output only the latest job. Note that can be empty > > indicating that it is the current job. > > > > Basically I want to order by jobs/job/EndDate in descending fashion and > > select only the first record.. > > > > How do I do that using xquery? > > > > Input request: > > > > > > > > qq > > qq > > > > > > > > > > 123 > > aaa bbb > > > > > > Analyst > > 1 > > 01-01-2015 > > 08-30-2015 > > > > > > Programmer > > 2 > > 08-31-2015 > > > > > > > > > > > > > > > > > > Expected output: > > > > > > > > > > qq > > qq > > > > > > > > > > 123 > > aaa bbb > > > > > > Programmer > > 2 > > 08-31-2015 > > > > > > > > > > > > > > > > > > Your help is greatly appreciated. > > > > > > > > > > > _______________________________________________ > > talk at x-query.com > > http://x-query.com/mailman/listinfo/talk > > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From mrys at microsoft.com Mon Nov 2 16:56:10 2015 From: mrys at microsoft.com (Michael Rys) Date: Tue, 3 Nov 2015 00:56:10 +0000 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> Message-ID: No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). Let me know if you want a personal demo :). Cheers Michael -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of daniela florescu Sent: Saturday, October 31, 2015 2:05 PM To: talk Subject: [xquery-talk] specification for Microsoft's U-SQL ? Seems interesting in principle. https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d But anyone in a luck to see a specification for it ? Thanks for any pointer, best regards Dana _______________________________________________ talk at x-query.com https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d From g at 28.io Tue Nov 3 01:51:25 2015 From: g at 28.io (Ghislain Fourny) Date: Tue, 3 Nov 2015 10:51:25 +0100 Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: <56379D12.2000702@rpbourret.com> References: <357302902.855057.1446472430000.JavaMail.yahoo@mail.yahoo.com> <56379D12.2000702@rpbourret.com> Message-ID: Hi Ronald, You can also use a count clause if you have XQuery 3.0! It makes it easier to read. Like so: for $job in doc('x.xml')//job order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2")) descending count $position where $position eq 1 return $job I hope it helps. Kind regards, Ghislain On Mon, Nov 2, 2015 at 6:27 PM, Ronald Bourret wrote: > Can't use just use a predicate that returns the first element in the > sorted sequence? Something like: > > let $seq = for $job in doc('x.xml')//job > order by > xs:date(replace($job/StartDate, > "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") > ) descending > return $job > return $seq[1] > > (My apologies if the syntax isn't exact. I haven't written an XQuery for > quite a while.) > > -- Ron > > On 11/2/2015 5:53 AM, sudheshna iyer wrote: > >> Thank you very much, Christian. Let me try this.. >> >> >> >> ------------------------------------------------------------------------ >> *From:* Christian Gr?n >> *To:* sudheshna iyer >> *Cc:* "talk at x-query.com" >> *Sent:* Sunday, November 1, 2015 4:26 PM >> *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record >> >> If your XQuery processor supports XQuery Update, this would be one >> solution: >> >> copy $xml := doc('x.xml') >> modify ( >> delete node subsequence( >> for $job in $xml//job >> order by xs:date(replace($job/StartDate, >> "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") >> ) descending >> return $job >> , 2) >> ) >> return $xml >> >> Best, >> Christian >> >> >> >> >> On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > > wrote: >> > Team, >> > >> > I have an xml which has multiple jobs elements. I want to sort the >> jobs and >> > want to output only the latest job. Note that can be empty >> > indicating that it is the current job. >> > >> > Basically I want to order by jobs/job/EndDate in descending fashion and >> > select only the first record.. >> > >> > How do I do that using xquery? >> > >> > Input request: >> > >> > >> > >> > qq >> > qq >> > >> > >> > >> > >> > 123 >> > aaa bbb >> > >> > >> > Analyst >> > 1 >> > 01-01-2015 >> > 08-30-2015 >> > >> > >> > Programmer >> > 2 >> > 08-31-2015 >> > >> > >> > >> > >> > >> > >> > >> > >> > Expected output: >> > >> > >> > >> > >> > qq >> > qq >> > >> > >> > >> > >> > 123 >> > aaa bbb >> > >> > >> > Programmer >> > 2 >> > 08-31-2015 >> > >> > >> > >> > >> > >> > >> > >> > >> > Your help is greatly appreciated. >> >> > >> > >> > >> > >> > _______________________________________________ >> > talk at x-query.com >> > http://x-query.com/mailman/listinfo/talk >> >> >> >> >> >> _______________________________________________ >> talk at x-query.com >> http://x-query.com/mailman/listinfo/talk >> >> > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From g at 28.io Tue Nov 3 02:03:48 2015 From: g at 28.io (Ghislain Fourny) Date: Tue, 3 Nov 2015 11:03:48 +0100 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> Message-ID: Hi Michael, Apologies in advance, as I anticipate it may be a stupid question -- but I couldn't find it by just goog..., pardon my French, binging :-p around: Why the choice of the letter U? :-) Unify? Kind regards, Ghislain On Tue, Nov 3, 2015 at 1:56 AM, Michael Rys wrote: > No formal specification. Just a language reference that is still under > development :). See http://aka.ms/usql_reference (and pardon the format, > I am writing it and our doc people "convert" it). > > Let me know if you want a personal demo :). > > Cheers > Michael > > -----Original Message----- > From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On > Behalf Of daniela florescu > Sent: Saturday, October 31, 2015 2:05 PM > To: talk > Subject: [xquery-talk] specification for Microsoft's U-SQL ? > > Seems interesting in principle. > > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d > > But anyone in a luck to see a specification for it ? > > Thanks for any pointer, best regards > Dana > _______________________________________________ > talk at x-query.com > > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dflorescu at me.com Tue Nov 3 22:23:51 2015 From: dflorescu at me.com (daniela florescu) Date: Tue, 03 Nov 2015 22:23:51 -0800 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> Message-ID: <0824267F-3CF9-421D-AD35-8C938BB4E935@me.com> Dear Michael, Thanks for the pointers. I was looking at https://azure.microsoft.com/en-us/documentation/articles/data-lake-analytics-u-sql-get-started/ and trying to understand the big picture from examples. So U-SQL is a dataflow scripting language, where the basic data model is a set of rows with C# types, and each step in the data flow is an expression that can mix (at many levels) SQL?s Select-from-where constructs with C# code. That?s what I understand at least. Let me know if I got it wrong. Seems very useful for expressing complex data transformations of all kinds, and it is still optimizable. Much more useful for ?data science? (whatever this big word means..) then the series of SQL-wannabes languages from the NoSQL vendors. Thanks, best regards Dana > On Nov 2, 2015, at 4:56 PM, Michael Rys wrote: > > No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). > > Let me know if you want a personal demo :). > > Cheers > Michael > > -----Original Message----- > From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of daniela florescu > Sent: Saturday, October 31, 2015 2:05 PM > To: talk > Subject: [xquery-talk] specification for Microsoft's U-SQL ? > > Seems interesting in principle. > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d > > But anyone in a luck to see a specification for it ? > > Thanks for any pointer, best regards > Dana > _______________________________________________ > talk at x-query.com > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d -------------- next part -------------- An HTML attachment was scrubbed... URL: From dflorescu at me.com Tue Nov 3 22:24:28 2015 From: dflorescu at me.com (daniela florescu) Date: Tue, 03 Nov 2015 22:24:28 -0800 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> Message-ID: <2A6639AC-5247-443F-8384-70AAF2749F14@me.com> Dear Michael, Thanks for the pointers. I was looking at https://azure.microsoft.com/en-us/documentation/articles/data-lake-analytics-u-sql-get-started/ and trying to understand the big picture from examples. So U-SQL is a dataflow scripting language, where the basic data model is a set of rows with C# types, and each step in the data flow is an expression that can mix (at many levels) SQL?s Select-from-where constructs with C# code. That?s what I understand at least. Let me know if I got it wrong. Seems very useful for expressing complex data transformations of all kinds, and it is still optimizable. Much more useful for ?data science? (whatever this big word means..) then the series of SQL-wannabes languages from the NoSQL vendors. Thanks, best regards Dana > On Nov 2, 2015, at 4:56 PM, Michael Rys > wrote: > > No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). > > Let me know if you want a personal demo :). > > Cheers > Michael > > -----Original Message----- > From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com ] On Behalf Of daniela florescu > Sent: Saturday, October 31, 2015 2:05 PM > To: talk > > Subject: [xquery-talk] specification for Microsoft's U-SQL ? > > Seems interesting in principle. > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d > > But anyone in a luck to see a specification for it ? > > Thanks for any pointer, best regards > Dana > _______________________________________________ > talk at x-query.com > https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d -------------- next part -------------- An HTML attachment was scrubbed... URL: From dflorescu at me.com Wed Nov 4 00:39:11 2015 From: dflorescu at me.com (daniela florescu) Date: Wed, 04 Nov 2015 00:39:11 -0800 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: <0824267F-3CF9-421D-AD35-8C938BB4E935@me.com> References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> <0824267F-3CF9-421D-AD35-8C938BB4E935@me.com> Message-ID: Dear Michael, I still have a question: can we use U-SQL to process JSON or XML? I could?t see a way of doing this ? as they are not flat rows? So is it possible ? Thanks, regards Dana > On Nov 3, 2015, at 10:23 PM, daniela florescu wrote: > > Dear Michael, > > Thanks for the pointers. > > I was looking at https://azure.microsoft.com/en-us/documentation/articles/data-lake-analytics-u-sql-get-started/ > and trying to understand the big picture from examples. > > So U-SQL is a dataflow scripting language, where the basic data model is a set of rows with C# types, and each > step in the data flow is an expression that can mix (at many levels) SQL?s Select-from-where constructs with C# code. > > That?s what I understand at least. Let me know if I got it wrong. > > Seems very useful for expressing complex data transformations of all kinds, and it is still optimizable. > > Much more useful for ?data science? (whatever this big word means..) then the series of SQL-wannabes languages > from the NoSQL vendors. > > Thanks, best regards > Dana > > > >> On Nov 2, 2015, at 4:56 PM, Michael Rys > wrote: >> >> No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). >> >> Let me know if you want a personal demo :). >> >> Cheers >> Michael >> >> -----Original Message----- >> From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com ] On Behalf Of daniela florescu >> Sent: Saturday, October 31, 2015 2:05 PM >> To: talk > >> Subject: [xquery-talk] specification for Microsoft's U-SQL ? >> >> Seems interesting in principle. >> https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d >> >> But anyone in a luck to see a specification for it ? >> >> Thanks for any pointer, best regards >> Dana >> _______________________________________________ >> talk at x-query.com >> https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrys at microsoft.com Wed Nov 4 12:08:40 2015 From: mrys at microsoft.com (Michael Rys) Date: Wed, 4 Nov 2015 20:08:40 +0000 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> <0824267F-3CF9-421D-AD35-8C938BB4E935@me.com> Message-ID: Dear Dana You have the ability to either flow JSON or XML as (currently) byte arrays or strings and use C# libraries such as NewtonSoft, System.XML or your own ? to process them. Or you can use an XML or JSON extractor (we currently have one of each published as samples on the U-SQL github repo), to extract parts of a JSON or XML document and map parts onto rows (some columns in turns can be maps or arrays). So it is not taking the route of XQuery or JSONiq in terms of processing arbitrary nested trees without the need of transformations (yet). To answer your questions inline: U-SQL is a query language more than a scripting language in that it does not provide snapshots or states inside a U-SQL ?script?. However, the syntax of step-wise refinement and composition is closer to a scripting language experience than for example the equivalent common-table-expressions that you normally see in ANSI SQL dialects. And yes you are right regarding the composition. I would recommend the following blog post to give you some more background about the language philosophy: http://blogs.msdn.com/b/visualstudio/archive/2015/09/28/introducing-u-sql.aspx. It is and evolution of SCOPE (see link in blog post). Cheers Michael From: daniela florescu [mailto:dflorescu at me.com] Sent: Wednesday, November 4, 2015 12:39 AM To: Michael Rys Cc: talk Subject: Re: [xquery-talk] specification for Microsoft's U-SQL ? Importance: High Dear Michael, I still have a question: can we use U-SQL to process JSON or XML? I could?t see a way of doing this ? as they are not flat rows? So is it possible ? Thanks, regards Dana On Nov 3, 2015, at 10:23 PM, daniela florescu > wrote: Dear Michael, Thanks for the pointers. I was looking at https://azure.microsoft.com/en-us/documentation/articles/data-lake-analytics-u-sql-get-started/ and trying to understand the big picture from examples. So U-SQL is a dataflow scripting language, where the basic data model is a set of rows with C# types, and each step in the data flow is an expression that can mix (at many levels) SQL?s Select-from-where constructs with C# code. That?s what I understand at least. Let me know if I got it wrong. Seems very useful for expressing complex data transformations of all kinds, and it is still optimizable. Much more useful for ?data science? (whatever this big word means..) then the series of SQL-wannabes languages from the NoSQL vendors. Thanks, best regards Dana On Nov 2, 2015, at 4:56 PM, Michael Rys > wrote: No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). Let me know if you want a personal demo :). Cheers Michael -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of daniela florescu Sent: Saturday, October 31, 2015 2:05 PM To: talk > Subject: [xquery-talk] specification for Microsoft's U-SQL ? Seems interesting in principle. https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d But anyone in a luck to see a specification for it ? Thanks for any pointer, best regards Dana _______________________________________________ talk at x-query.com https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrys at microsoft.com Wed Nov 4 13:33:26 2015 From: mrys at microsoft.com (Michael Rys) Date: Wed, 4 Nov 2015 21:33:26 +0000 Subject: [xquery-talk] specification for Microsoft's U-SQL ? In-Reply-To: References: <93679119-E2DC-49E8-95E4-5789B959E15E@me.com> Message-ID: Officially it is for Unifying? Inofficial variants I will provide over a beer ?. Cheers Michael From: Ghislain Fourny [mailto:g at 28.io] Sent: Tuesday, November 3, 2015 2:04 AM To: Michael Rys Cc: daniela florescu ; talk Subject: Re: [xquery-talk] specification for Microsoft's U-SQL ? Importance: High Hi Michael, Apologies in advance, as I anticipate it may be a stupid question -- but I couldn't find it by just goog..., pardon my French, binging :-p around: Why the choice of the letter U? :-) Unify? Kind regards, Ghislain On Tue, Nov 3, 2015 at 1:56 AM, Michael Rys > wrote: No formal specification. Just a language reference that is still under development :). See http://aka.ms/usql_reference (and pardon the format, I am writing it and our doc people "convert" it). Let me know if you want a personal demo :). Cheers Michael -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of daniela florescu Sent: Saturday, October 31, 2015 2:05 PM To: talk > Subject: [xquery-talk] specification for Microsoft's U-SQL ? Seems interesting in principle. https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fthenewstack.io%2fmeet-u-sql-microsofts-new-language-big-data%2f&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=iZjmF47tPZ316GAyjeXegMSLOq%2bLFAbo3zvRYOwMPy0%3d But anyone in a luck to see a specification for it ? Thanks for any pointer, best regards Dana _______________________________________________ talk at x-query.com https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fx-query.com%2fmailman%2flistinfo%2ftalk&data=01%7c01%7cmrys%40microsoft.com%7caef4ceeec92543784b5608d2e23771f1%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=dJTn2RgYiSUgZH5GU3e3CsLqpCj9Gvd6uI%2fGS7JomP8%3d _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From dflorescu at me.com Sat Nov 7 19:12:37 2015 From: dflorescu at me.com (daniela florescu) Date: Sat, 07 Nov 2015 19:12:37 -0800 Subject: [xquery-talk] after Microsoft, here comes Oracle's version of query/scripting language, LiveSQL Message-ID: <0269D332-5899-4A5C-838E-23CC32A04D55@me.com> https://livesql.oracle.com/apex/livesql/file/index.html I looked a little bit at the XML and JSON part and so far not impressed at all. E.g I?ve been trying to mentally parse this example for 15 minutes, without success. https://livesql.oracle.com/apex/livesql/file/content_CBARSVE1HWW2UJACTPV56V5WI.html I have no idea what it is supposed to mean?. E.g This example is probably intended to show windowing but all queries in the tutorial end up with errors ?:( https://livesql.oracle.com/apex/livesql/file/content_O8LN6RU99K8TXRKXDN6GX1HDL.html Dana From dflorescu at me.com Sat Nov 7 19:20:32 2015 From: dflorescu at me.com (daniela florescu) Date: Sat, 07 Nov 2015 19:20:32 -0800 Subject: [xquery-talk] after Microsoft, here comes Oracle's version of query/scripting language, LiveSQL In-Reply-To: <0269D332-5899-4A5C-838E-23CC32A04D55@me.com> References: <0269D332-5899-4A5C-838E-23CC32A04D55@me.com> Message-ID: <9F021031-5A05-4F82-880C-7BAC6CBA8BB9@me.com> I am sorry, I think I misunderstood the blog?.it is just the editor in the browser that is new, not the language. Good old PL/SQL underneath, I guess !? In fact I cannot tell. Some things are old, some things in the language seem new?.so for the moment I am just confused. Best Dana > On Nov 7, 2015, at 7:12 PM, daniela florescu wrote: > > https://livesql.oracle.com/apex/livesql/file/index.html > > I looked a little bit at the XML and JSON part and so far not impressed at all. > > E.g I?ve been trying to mentally parse this example for 15 minutes, without success. > https://livesql.oracle.com/apex/livesql/file/content_CBARSVE1HWW2UJACTPV56V5WI.html > I have no idea what it is supposed to mean?. > > E.g This example is probably intended to show windowing but all queries in the tutorial end up with > errors ?:( > https://livesql.oracle.com/apex/livesql/file/content_O8LN6RU99K8TXRKXDN6GX1HDL.html > > Dana > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From wshager at gmail.com Fri Nov 13 02:45:01 2015 From: wshager at gmail.com (W.S. Hager) Date: Fri, 13 Nov 2015 11:45:01 +0100 Subject: [xquery-talk] import module Message-ID: Hi, Why is it "import module" and not "import"? Can something other then a module be imported? Thanks, Wouter -- W.S. Hager Lagua Web Solutions http://lagua.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From wshager at gmail.com Fri Nov 13 02:46:24 2015 From: wshager at gmail.com (W.S. Hager) Date: Fri, 13 Nov 2015 11:46:24 +0100 Subject: [xquery-talk] import module In-Reply-To: References: Message-ID: Ah, I found it: import schema. Nevermind. 2015-11-13 11:45 GMT+01:00 W.S. Hager : > Hi, > > Why is it "import module" and not "import"? Can something other then a > module be imported? > > Thanks, > Wouter > > -- > > W.S. Hager > Lagua Web Solutions > http://lagua.nl > -- W.S. Hager Lagua Web Solutions http://lagua.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From sudheshnaiyer at yahoo.com Sun Nov 15 00:11:50 2015 From: sudheshnaiyer at yahoo.com (sudheshna iyer) Date: Sun, 15 Nov 2015 08:11:50 +0000 (UTC) Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: References: Message-ID: <518117893.5429291.1447575110930.JavaMail.yahoo@mail.yahoo.com> Thank you all for the reply. Just need one more modification to this. ?In the input if the StartDate is blank, then I should consider that as the current job and return the job that has blank as the output.? If there are no jobs which have startDate as blank, then it should return the recent startdate job (for which we already have the response as shown in email chain,,) For eg, in the below case, response should be the job element with id = 1:?? ?? ? ? qq? ? ? qq? ?? ?? ? ? ? ? ? ? ?? ? ? ? ? ? 123? ? ? ? ? ? aaa bbb? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? Analyst? ? ? ? ? ? ? ? ? 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1? ? ? ? ? ? ? ?? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? Programmer? ? ? ? ? ? ? ? ? 2? ? ? ? ? ? ? ? ? 08-31-2015? ? ? ? ? ? ? ? ?2? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? From: Ghislain Fourny To: Ronald Bourret Cc: "talk at x-query.com" ; sudheshna iyer Sent: Tuesday, November 3, 2015 4:51 AM Subject: Re: [xquery-talk] Xquery : Sort and get only the first record Hi Ronald, You can also use a count clause if you have XQuery 3.0! It makes it easier to read. Like so: for $job in doc('x.xml')//job order by?xs:date(replace($job/StartDate,?"(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2")) descending count $position where $position eq 1 return $job I hope it helps. Kind regards,Ghislain On Mon, Nov 2, 2015 at 6:27 PM, Ronald Bourret wrote: Can't use just use a predicate that returns the first element in the sorted sequence? Something like: ? let $seq = for $job in doc('x.xml')//job ? ? ? ? ? ? ?order by ? ? ? ? ? ? ? ? xs:date(replace($job/StartDate, ? ? ? ? ? ? ? ? ? ? ? ? "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ? ? ? ? ? ? ? ? ? ? ? ?) descending ? ? ? ? ? ? ?return $job ? return $seq[1] (My apologies if the syntax isn't exact. I haven't written an XQuery for quite a while.) -- Ron On 11/2/2015 5:53 AM, sudheshna iyer wrote: Thank you very much, Christian. Let me try this.. ------------------------------------------------------------------------ *From:* Christian Gr?n *To:* sudheshna iyer *Cc:* "talk at x-query.com" *Sent:* Sunday, November 1, 2015 4:26 PM *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record If your XQuery processor supports XQuery Update, this would be one solution: ? ?copy $xml := doc('x.xml') ? ?modify ( ? ? ?delete node subsequence( ? ? ? ?for $job in $xml//job ? ? ? ?order by xs:date(replace($job/StartDate, ? ? ? ? ?"(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ? ? ? ?) descending ? ? ? ?return $job ? ? ?, 2) ? ?) ? ?return $xml Best, Christian On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > wrote: ?> Team, ?> ?> I have an xml which has multiple jobs elements. I want to sort the jobs and ?> want to output only the latest job. Note that can be empty ?> indicating that it is the current job. ?> ?> Basically I want to order by jobs/job/EndDate in descending fashion and ?> select only the first record.. ?> ?> How do I do that using xquery? ?> ?> Input request: ?> ?> ?>? ?>? ? ? qq ?>? ? ? qq ?>? ?>? ?>? ? ? ?>? ? ? ? ?>? ? ? ? ? ? 123 ?>? ? ? ? ? ? aaa bbb ?>? ? ? ? ? ? ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ? ? Analyst ?>? ? ? ? ? ? ? ? ? 1 ?>? ? ? ? ? ? ? ? ? 01-01-2015 ?>? ? ? ? ? ? ? ? ? 08-30-2015 ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ? ? Programmer ?>? ? ? ? ? ? ? ? ? 2 ?>? ? ? ? ? ? ? ? ? 08-31-2015 ?>? ? ? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ?>? ? ? ? ?>? ? ? ?>? ?> ?> ?> Expected output: ?> ?> ?> ?>? ?>? ? ? qq ?>? ? ? qq ?>? ?>? ?>? ? ? ?>? ? ? ? ?>? ? ? ? ? ? 123 ?>? ? ? ? ? ? aaa bbb ?>? ? ? ? ? ? ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ? ? Programmer ?>? ? ? ? ? ? ? ? ? 2 ?>? ? ? ? ? ? ? ? ? 08-31-2015 ?>? ? ? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ?>? ? ? ? ? ? ?>? ? ? ? ?>? ? ? ?>? ?> ?> ?> Your help is greatly appreciated. ?> ?> ?> ?> ?> _______________________________________________ ?> talk at x-query.com ?> http://x-query.com/mailman/listinfo/talk _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From christian.gruen at gmail.com Sun Nov 15 01:35:22 2015 From: christian.gruen at gmail.com (=?UTF-8?Q?Christian_Gr=C3=BCn?=) Date: Sun, 15 Nov 2015 10:35:22 +0100 Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: <518117893.5429291.1447575110930.JavaMail.yahoo@mail.yahoo.com> References: <518117893.5429291.1447575110930.JavaMail.yahoo@mail.yahoo.com> Message-ID: How does your current XQuery expression look like? On Sun, Nov 15, 2015 at 9:11 AM, sudheshna iyer wrote: > Thank you all for the reply. > > Just need one more modification to this. In the input if the StartDate is > blank, then I should consider that as the current job and return the job > that has blank as the output. > > If there are no jobs which have startDate as blank, then it should return > the recent startdate job (for which we already have the response as shown in > email chain,,) > > For eg, in the below case, response should be the job element with id = 1: > > > > qq > qq > > > > > 123 > aaa bbb > > > Analyst > 1 > > 1 > > > Programmer > 2 > 08-31-2015 > 2 > > > > > > > > > > > ________________________________ > From: Ghislain Fourny > To: Ronald Bourret > Cc: "talk at x-query.com" ; sudheshna iyer > > Sent: Tuesday, November 3, 2015 4:51 AM > Subject: Re: [xquery-talk] Xquery : Sort and get only the first record > > Hi Ronald, > > You can also use a count clause if you have XQuery 3.0! It makes it easier > to read. Like so: > > for $job in doc('x.xml')//job > order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", > "$3-$1-$2")) descending > count $position > where $position eq 1 > return $job > > I hope it helps. > > Kind regards, > Ghislain > > > > > On Mon, Nov 2, 2015 at 6:27 PM, Ronald Bourret > wrote: > > Can't use just use a predicate that returns the first element in the sorted > sequence? Something like: > > let $seq = for $job in doc('x.xml')//job > order by > xs:date(replace($job/StartDate, > "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") > ) descending > return $job > return $seq[1] > > (My apologies if the syntax isn't exact. I haven't written an XQuery for > quite a while.) > > -- Ron > > On 11/2/2015 5:53 AM, sudheshna iyer wrote: > > Thank you very much, Christian. Let me try this.. > > > > ------------------------------------------------------------------------ > *From:* Christian Gr?n > *To:* sudheshna iyer > *Cc:* "talk at x-query.com" > *Sent:* Sunday, November 1, 2015 4:26 PM > *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record > > If your XQuery processor supports XQuery Update, this would be one solution: > > copy $xml := doc('x.xml') > modify ( > delete node subsequence( > for $job in $xml//job > order by xs:date(replace($job/StartDate, > "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") > ) descending > return $job > , 2) > ) > return $xml > > Best, > Christian > > > > > On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > wrote: > > Team, > > > > I have an xml which has multiple jobs elements. I want to sort the > jobs and > > want to output only the latest job. Note that can be empty > > indicating that it is the current job. > > > > Basically I want to order by jobs/job/EndDate in descending fashion and > > select only the first record.. > > > > How do I do that using xquery? > > > > Input request: > > > > > > > > qq > > qq > > > > > > > > > > 123 > > aaa bbb > > > > > > Analyst > > 1 > > 01-01-2015 > > 08-30-2015 > > > > > > Programmer > > 2 > > 08-31-2015 > > > > > > > > > > > > > > > > > > Expected output: > > > > > > > > > > qq > > qq > > > > > > > > > > 123 > > aaa bbb > > > > > > Programmer > > 2 > > 08-31-2015 > > > > > > > > > > > > > > > > > > Your help is greatly appreciated. > > > > > > > > > > > _______________________________________________ > > talk at x-query.com > > http://x-query.com/mailman/listinfo/talk > > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From sudheshnaiyer at yahoo.com Sat Nov 21 16:42:18 2015 From: sudheshnaiyer at yahoo.com (sudheshna iyer) Date: Sun, 22 Nov 2015 00:42:18 +0000 (UTC) Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: References: Message-ID: <2124391546.8776721.1448152938691.JavaMail.yahoo@mail.yahoo.com> Currently below works for me: for $job in //joborder by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2")) descendingcount $positionwhere $position eq 1return $job To this, I want to add:> Just need one more modification to this.? In the input if the StartDate is > blank, then I should consider that as the current job and return the job > that has blank as the output. Thank you for your response. From: Christian Gr?n To: sudheshna iyer Cc: "talk at x-query.com" Sent: Sunday, November 15, 2015 4:35 AM Subject: Re: [xquery-talk] Xquery : Sort and get only the first record How does your current XQuery expression look like? On Sun, Nov 15, 2015 at 9:11 AM, sudheshna iyer wrote: > Thank you all for the reply. > > Just need one more modification to this.? In the input if the StartDate is > blank, then I should consider that as the current job and return the job > that has blank as the output. > > If there are no jobs which have startDate as blank, then it should return > the recent startdate job (for which we already have the response as shown in > email chain,,) > > For eg, in the below case, response should be the job element with id = 1: > > >? ? >? ? ? qq >? ? ? qq >? ? >? ? >? ? ? >? ? ? ? ? >? ? ? ? ? ? 123 >? ? ? ? ? ? aaa bbb >? ? ? ? ? ? >? ? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? Analyst >? ? ? ? ? ? ? ? ? 1 >? ? ? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? 1 >? ? ? ? ? ? ? ? >? ? ? ? ? ? ? ? >? ? ? ? ? ? ? ? ? Programmer >? ? ? ? ? ? ? ? ? 2 >? ? ? ? ? ? ? ? ? 08-31-2015 >? ? ? ? ? ? ? ? ? 2 >? ? ? ? ? ? ? ? >? ? ? ? ? ? >? ? ? ? ? >? ? ? >? ? > > > > > > ________________________________ > From: Ghislain Fourny > To: Ronald Bourret > Cc: "talk at x-query.com" ; sudheshna iyer > > Sent: Tuesday, November 3, 2015 4:51 AM > Subject: Re: [xquery-talk] Xquery : Sort and get only the first record > > Hi Ronald, > > You can also use a count clause if you have XQuery 3.0! It makes it easier > to read. Like so: > > for $job in doc('x.xml')//job > order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", > "$3-$1-$2")) descending > count $position > where $position eq 1 > return $job > > I hope it helps. > > Kind regards, > Ghislain > > > > > On Mon, Nov 2, 2015 at 6:27 PM, Ronald Bourret > wrote: > > Can't use just use a predicate that returns the first element in the sorted > sequence? Something like: > >? let $seq = for $job in doc('x.xml')//job >? ? ? ? ? ? ? order by >? ? ? ? ? ? ? ? xs:date(replace($job/StartDate, >? ? ? ? ? ? ? ? ? ? ? ? "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") >? ? ? ? ? ? ? ? ? ? ? ? ) descending >? ? ? ? ? ? ? return $job >? return $seq[1] > > (My apologies if the syntax isn't exact. I haven't written an XQuery for > quite a while.) > > -- Ron > > On 11/2/2015 5:53 AM, sudheshna iyer wrote: > > Thank you very much, Christian. Let me try this.. > > > > ------------------------------------------------------------------------ > *From:* Christian Gr?n > *To:* sudheshna iyer > *Cc:* "talk at x-query.com" > *Sent:* Sunday, November 1, 2015 4:26 PM > *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record > > If your XQuery processor supports XQuery Update, this would be one solution: > >? ? copy $xml := doc('x.xml') >? ? modify ( >? ? ? delete node subsequence( >? ? ? ? for $job in $xml//job >? ? ? ? order by xs:date(replace($job/StartDate, >? ? ? ? ? "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") >? ? ? ? ) descending >? ? ? ? return $job >? ? ? , 2) >? ? ) >? ? return $xml > > Best, > Christian > > > > > On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > wrote: >? > Team, >? > >? > I have an xml which has multiple jobs elements. I want to sort the > jobs and >? > want to output only the latest job. Note that can be empty >? > indicating that it is the current job. >? > >? > Basically I want to order by jobs/job/EndDate in descending fashion and >? > select only the first record.. >? > >? > How do I do that using xquery? >? > >? > Input request: >? > >? > >? >? >? >? ? ? qq >? >? ? ? qq >? >? >? >? >? >? ? ? >? >? ? ? ? >? >? ? ? ? ? ? 123 >? >? ? ? ? ? ? aaa bbb >? >? ? ? ? ? ? >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? ? ? ? Analyst >? >? ? ? ? ? ? ? ? ? 1 >? >? ? ? ? ? ? ? ? ? 01-01-2015 >? >? ? ? ? ? ? ? ? ? 08-30-2015 >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? ? ? ? Programmer >? >? ? ? ? ? ? ? ? ? 2 >? >? ? ? ? ? ? ? ? ? 08-31-2015 >? >? ? ? ? ? ? ? ? ? >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? >? >? ? ? ? >? >? ? ? >? >? >? > >? > >? > Expected output: >? > >? > >? > >? >? >? >? ? ? qq >? >? ? ? qq >? >? >? >? >? >? ? ? >? >? ? ? ? >? >? ? ? ? ? ? 123 >? >? ? ? ? ? ? aaa bbb >? >? ? ? ? ? ? >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? ? ? ? Programmer >? >? ? ? ? ? ? ? ? ? 2 >? >? ? ? ? ? ? ? ? ? 08-31-2015 >? >? ? ? ? ? ? ? ? ? >? >? ? ? ? ? ? ? >? >? ? ? ? ? ? >? >? ? ? ? >? >? ? ? >? >? >? > >? > >? > Your help is greatly appreciated. > >? > >? > >? > >? > >? > _______________________________________________ >? > talk at x-query.com >? > http://x-query.com/mailman/listinfo/talk > > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From christian.gruen at gmail.com Sun Nov 22 23:43:42 2015 From: christian.gruen at gmail.com (=?UTF-8?Q?Christian_Gr=C3=BCn?=) Date: Mon, 23 Nov 2015 08:43:42 +0100 Subject: [xquery-talk] Xquery : Sort and get only the first record In-Reply-To: <2124391546.8776721.1448152938691.JavaMail.yahoo@mail.yahoo.com> References: <2124391546.8776721.1448152938691.JavaMail.yahoo@mail.yahoo.com> Message-ID: This is one solution, using "empty greatest" (missing dates will be returned first in the ordered results): for $job in //job order by $job/StartDate/text()/xs:date( replace(., "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") ) descending empty greatest count $position where $position eq 1 return $job The following one may be more intuitive: for $job in //job let $startDate := $job/StartDate/text() order by ( if($startDate) then ( xs:date(replace($startDate, "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2")) ) else () ) descending empty greatest count $position where $position eq 1 return $job Cheers, Christian ______________________________________ On Sun, Nov 22, 2015 at 1:42 AM, sudheshna iyer wrote: > Currently below works for me: > > for $job in //job > order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", > "$3-$1-$2")) descending > count $position > where $position eq 1 > return $job > > To this, I want to add: >> Just need one more modification to this. In the input if the StartDate is >> blank, then I should consider that as the current job and return the job >> that has blank as the output. > > > Thank you for your response. > > ________________________________ > From: Christian Gr?n > To: sudheshna iyer > Cc: "talk at x-query.com" > Sent: Sunday, November 15, 2015 4:35 AM > > Subject: Re: [xquery-talk] Xquery : Sort and get only the first record > > How does your current XQuery expression look like? > > > On Sun, Nov 15, 2015 at 9:11 AM, sudheshna iyer > wrote: >> Thank you all for the reply. >> >> Just need one more modification to this. In the input if the StartDate is >> blank, then I should consider that as the current job and return the job >> that has blank as the output. >> >> If there are no jobs which have startDate as blank, then it should return >> the recent startdate job (for which we already have the response as shown >> in >> email chain,,) >> >> For eg, in the below case, response should be the job element with id = 1: >> >> >> >> qq >> qq >> >> >> >> >> 123 >> aaa bbb >> >> >> Analyst >> 1 >> >> 1 >> >> >> Programmer >> 2 >> 08-31-2015 >> 2 >> >> >> >> >> >> >> >> >> >> >> ________________________________ >> From: Ghislain Fourny >> To: Ronald Bourret >> Cc: "talk at x-query.com" ; sudheshna iyer >> >> Sent: Tuesday, November 3, 2015 4:51 AM >> Subject: Re: [xquery-talk] Xquery : Sort and get only the first record >> >> Hi Ronald, >> >> You can also use a count clause if you have XQuery 3.0! It makes it easier >> to read. Like so: >> >> for $job in doc('x.xml')//job >> order by xs:date(replace($job/StartDate, "(\d{2})-(\d{2})-(\d{4})", >> "$3-$1-$2")) descending >> count $position >> where $position eq 1 >> return $job >> >> I hope it helps. >> >> Kind regards, >> Ghislain >> >> >> >> >> On Mon, Nov 2, 2015 at 6:27 PM, Ronald Bourret >> wrote: >> >> Can't use just use a predicate that returns the first element in the >> sorted >> sequence? Something like: >> >> let $seq = for $job in doc('x.xml')//job >> order by >> xs:date(replace($job/StartDate, >> "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") >> ) descending >> return $job >> return $seq[1] >> >> (My apologies if the syntax isn't exact. I haven't written an XQuery for >> quite a while.) >> >> -- Ron >> >> On 11/2/2015 5:53 AM, sudheshna iyer wrote: >> >> Thank you very much, Christian. Let me try this.. >> >> >> >> ------------------------------------------------------------------------ >> *From:* Christian Gr?n >> *To:* sudheshna iyer >> *Cc:* "talk at x-query.com" >> *Sent:* Sunday, November 1, 2015 4:26 PM >> *Subject:* Re: [xquery-talk] Xquery : Sort and get only the first record >> >> If your XQuery processor supports XQuery Update, this would be one >> solution: >> >> copy $xml := doc('x.xml') >> modify ( >> delete node subsequence( >> for $job in $xml//job >> order by xs:date(replace($job/StartDate, >> "(\d{2})-(\d{2})-(\d{4})", "$3-$1-$2") >> ) descending >> return $job >> , 2) >> ) >> return $xml >> >> Best, >> Christian >> >> >> >> >> On Sun, Nov 1, 2015 at 8:51 PM, sudheshna iyer > > wrote: >> > Team, >> > >> > I have an xml which has multiple jobs elements. I want to sort the >> jobs and >> > want to output only the latest job. Note that can be empty >> > indicating that it is the current job. >> > >> > Basically I want to order by jobs/job/EndDate in descending fashion and >> > select only the first record.. >> > >> > How do I do that using xquery? >> > >> > Input request: >> > >> > >> > >> > qq >> > qq >> > >> > >> > >> > >> > 123 >> > aaa bbb >> > >> > >> > Analyst >> > 1 >> > 01-01-2015 >> > 08-30-2015 >> > >> > >> > Programmer >> > 2 >> > 08-31-2015 >> > >> > >> > >> > >> > >> > >> > >> > >> > Expected output: >> > >> > >> > >> > >> > qq >> > qq >> > >> > >> > >> > >> > 123 >> > aaa bbb >> > >> > >> > Programmer >> > 2 >> > 08-31-2015 >> > >> > >> > >> > >> > >> > >> > >> > >> > Your help is greatly appreciated. >> >> > >> > >> > >> > >> > _______________________________________________ >> > talk at x-query.com >> > http://x-query.com/mailman/listinfo/talk >> >> >> >> >> >> _______________________________________________ >> talk at x-query.com >> http://x-query.com/mailman/listinfo/talk >> >> >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus > > > >> >> _______________________________________________ >> talk at x-query.com >> http://x-query.com/mailman/listinfo/talk >> >> >> >> _______________________________________________ >> talk at x-query.com >> http://x-query.com/mailman/listinfo/talk >> >> >> >> _______________________________________________ >> talk at x-query.com >> http://x-query.com/mailman/listinfo/talk > >