go to post Vitaliy Serdtsev · Sep 27, 2021 Yes. By default, a strictly defined list of packages/classes is displayed in IRIS for security purposes, but you can change this behavior locally.
go to post Vitaliy Serdtsev · Sep 27, 2021 In Caché all classes is visible, and in IRIS, you need to enable their display.
go to post Vitaliy Serdtsev · Sep 27, 2021 Or so: set tmp = ##class(%IO.StringStream).%New() do tmp.Write("This is my text") do tmp.Seek(11) do tmp.Write(" NEW") do tmp.Rewind() write tmp.Read(tmp.Size) ;This is my NEW text
go to post Vitaliy Serdtsev · Sep 23, 2021 See %SQL.StatementResult:%DisplayFormatted() Simple sample (for namespace "SAMPLES"): set st = ##class(%SQL.Statement).%New(2,"Sample") set sql = 3 set sql(1) = "select TOP 5 %ID as id, Name, DOB, Home_State" set sql(2) = "from Person where Age > 40" set sql(3) = "order by 2" do st.%Prepare(.sql) for type="txt","pdf","csv","html","xml" { set rs = st.%Execute() do rs.%DisplayFormatted(type,"C:\Temp\report") }As a result, the following files are generated: report.csv report.html report.pdf report.txt report.xml
go to post Vitaliy Serdtsev · Sep 17, 2021 Instead of set str=$e(str,1,*-1) , will be a little faster set $e(str,*)="" But this is already saving on matches. PS: for the sake of interest, I checked on a special version of Caché (very old) with server-side JavaScript (not to be confused with Node.js) Source code Include %occInclude Class dc.test [ Abstract ] { ClassMethod MakeStringOnJS(N) [ Language = javascript] { var myval="a", arr=[], stop, str, start=(new Date()).getTime(); for (var i=0;i<N;i++) arr[i]=myval; str=arr.join(); stop=(new Date()).getTime(); Cache.Console.WriteLine("[JavaScript] execution: ",stop-start,"(ms) len(str): ",str.length); // Force a Garbage Collection Cache.Class.$JavaScript_Runtime.$GarbageCollect(); } ClassMethod MakeStringOnCOS(N) { s myval="a", str="", time=$zh f i=1:1:N s str=str_myval_"," s $e(str,$l(str))="" ; not supported $e(str,*) w $$$FormatText("[COS] execution: %1(ms) len(str): %2",$zh-time*1000,$l(str)),! } /// d ##class(dc.test).Test() ClassMethod Test(N = 10) { d ..MakeStringOnJS(N), ..MakeStringOnCOS(N) } } USER>d ##class(dc.test).Test(1800000) [JavaScript] execution: 99(ms) len(str): 3599999 [COS] execution: 126.683(ms) len(str): 3599999 By the way, the JS code has almost no limit on the string size.
go to post Vitaliy Serdtsev · Sep 17, 2021 An example without complex formulas and very fast Include %DeepSee Class dc.test [ Abstract ] { ClassMethod FirstLastDayMonth( year = 2015, month = 2) { s mm=$$$iscPadZero(month,2), firstDay=$zdh(year_mm_"01",8), lastDay=$zdh(year_mm_$$$iscDaysInMonth(year,month),8), firstDayName=$zd(firstDay,12,,,,,,,,1), lastDayName=$zd(lastDay,12,,,,,,,,1) w $$$FormatText("firstDay = %1 (%2), lastDay = %3 (%4)",$zd(firstDay),firstDayName,$zd(lastDay),lastDayName),! } /// d ##class(dc.test).Test() ClassMethod Test() { d ..FirstLastDayMonth(2015,2), ..FirstLastDayMonth(2021,9) } } USER>d ##class(dc.test).Test() firstDay = 01.02.2015 (Sunday), lastDay = 28.02.2015 (Saturday) firstDay = 01.09.2021 (Wednesday), lastDay = 30.09.2021 (Thursday)
go to post Vitaliy Serdtsev · Sep 15, 2021 Did you look in the direction of %Stream.GlobalCharacterSearchable? See also Scalar Functions and Streams SELECT Notes Stream,DATALENGTH(Notes) lenStream,SUBSTRING(Notes,DATALENGTH(Notes)-9) AS StreamLast10Chars FROM Sample.Employee WHERE Notes IS NOT NULL
go to post Vitaliy Serdtsev · Sep 15, 2021 Simple sample: Class dc.test Extends %ZEN.Component.page { XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ] { <page xmlns="http://www.intersystems.com/zen"> <tablePane id="tp" sql="select 1 ID,'Western branch' Branch,{d '2021-03-15'} "Date",35 Suma union select 2,'Eastern branch',{d '2020-12-11'},37" /> <button caption="Row unselect" onclick="zenPage.rowUnselect()"/> </page> } ClientMethod rowUnselect() [ Language = javascript ] { var tp=zen('tp'); row=tp.selectedIndex; if (tp.rowSelect && row>=0) { var old=tp.enableToggleSelect; tp.enableToggleSelect=true; tp.selectRow(row); tp.enableToggleSelect=old; } } }
go to post Vitaliy Serdtsev · Sep 15, 2021 I also will insert my five kopecks. The %Library package also includes stream classes, but those are deprecated. The class library includes additional stream classes, but those are not intended for general use. Working with Streams I have %Stream.FileCharacter was an order of magnitude faster than %[Library.]File If you rewrite the line-by-line reading to read blocks with further parsing of lines, the speed will more increase by an order of magnitude. Sample Class dc.test [ Abstract ] { ClassMethod ReadCSVStream(fCSV As %String) As %String { s stream = ##class(%Stream.FileCharacter).%New() d stream.LinkToFile(fCSV) s time1=$zh While 'stream.AtEnd { s line=stream.ReadLine($$$MaxLocalLength) } s diff=$zh-time1 q diff } ClassMethod ReadCSVStreamBlock(fCSV As %String) As %String { s stream = ##class(%Stream.FileCharacter).%New() d stream.LinkToFile(fCSV) s i=0,time1=$zh While 'stream.AtEnd { s chunks($i(i))=stream.Read($$$MaxLocalLength) // do parsing chunk to lines } s diff=$zh-time1 q diff } ClassMethod ReadCSVOURC(fCSV As %String) As %String { o fCSV::1 e q "Missing File" s eof=$zu(68,40,1) u fCSV s time1=$zh f { r line q:$zeof // do something with line } s diff=$zh-time1 c fCSV d $zu(68,40,eof) q diff } /// d ##class(dc.test).Test() ClassMethod Test() { s ptr=0, clnm=$classname() &sql(select %dlist(Name) into :list from %Dictionary.CompiledMethod where Parent=:clnm and Name %startswith 'ReadCSV' group by Parent order by SequenceNumber) while $listnext(list,ptr,m) { w !,"[",m,"]",?20,"execution: ",$classmethod(clnm,m,"data.csv"),! } } } On the Internet, you can find a lot of materials about comparing the speed of reading files (in particular CSV) for different programming languages (Python, C/C++, R, C#, Java, etc.), for example (this is machine translation). Often, those who make such comparisons do not always know all these languages equally well, so sometimes casus happen. Who do you think in the article above was faster when reading 1e7+ lines: Fortran or C++ ? Fortran :) If we approach the issue formally, then the advantage will be given to compiled languages, not interpreted ones, as well as the implementation that uses all the capabilities of the operating system and hardware.
go to post Vitaliy Serdtsev · Sep 14, 2021 Example of using the import/export classes SQL Export Data with %SQL.ExportMgr
go to post Vitaliy Serdtsev · Sep 6, 2021 Caché SQL Optimization Guide New Video: Optimizing SQL Queries New Video: Optimizing Your SQL Queries SQL Performance Resources I think that's enough for a start ;)
go to post Vitaliy Serdtsev · Sep 6, 2021 Here you will find a lot of useful things in particular $QLENGTH: Using Globals
go to post Vitaliy Serdtsev · Aug 20, 2021 See Base64EncodeStream Or %Atelier.v1.Utils.General:Base64FromStream()
go to post Vitaliy Serdtsev · Aug 20, 2021 See documentation: $ZF(-100) requires the %System_Callout:U privilege. And check "Error Handling".