Vitaliy Serdtsev · Jun 23, 2022 go to post

See MultiValue Basic | Caché Alternative Exists for SOUNDEX()

Workaround:

Class dc.test Abstract ]
{

ClassMethod Test()
{
  
  ..SOUNDEX("M"),!

  ;or

  &sql(select SOUNDEX('McD'into :r)
  r,!
}

ClassMethod SOUNDEX(sAs %String Language = mvbasic, SqlName SOUNDEXSqlProc ]
{
 RETURN SOUNDEX(s)
}

}

Result:

USER>##class(dc.test).Test()
M000
M230
Vitaliy Serdtsev · May 17, 2022 go to post

Now on evaluation.intersystems.com for Windows/MacOSX/Container allows to download the version of IRIS 2020.1CE, and for the rest - IRIS 2021.2CE.

What happened and when will the problem with downloading the latest version disappear once and for all?

Vitaliy Serdtsev · May 13, 2022 go to post

It gives an incorrect result for some data, for example:

Detector("abbz", "abzz")
Detector("aaz", "azz")
Detector("azz", "aaz")

Vitaliy Serdtsev · May 13, 2022 go to post

Without loops:

 

size = 82 (likely the code can be further reduced)

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 a=$zu(28,a,6),b=$zu(28,b,6) q $l(a)=$l(b)&(a'=$tr(a,b,a_b))&(b'=$tr(b,a,b_a))
 ;or
 a=$zu(28,a,6),b=$zu(28,b,6) q $l(a)=$l(b)&(a'=$tr(a,b,a_b))&(a'=$tr(a,a_b,b))
}
Vitaliy Serdtsev · May 12, 2022 go to post

I follow a simple rule: first I change the data, and only then I put the constraints in the code. Not the other way around.

Vitaliy Serdtsev · May 12, 2022 go to post

Excellent work.yes

You have come up with an additional optimization different from mine. Your code can be improved to 66.

 

size = 68

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 i=65:1:91{q:$$r(a)'=$$r(b)i=91
r(x)q $l($$$UPPER(x),$c(i))
}
 

size = 67

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 i=0:1:91{q:$$r(a)'=$$r(b)i=91
r(x)q $l($zu(28,x,6),$c(i))
}

$$$ALPHAUP(x) == $zu(28,x,6)

 

size = 66

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 i=90:-1:0{q:$$r(a)'=$$r(b)'i
r(x)q $l($zu(28,x,6),$c(i))
}
Vitaliy Serdtsev · May 11, 2022 go to post

Ok.

 

size = 190

ClassMethod Compress(As %StringAs %String
{
a=$p(s,",",$i(i)),d=$p(s,",",i+1)-c=1:1{q:d*c+a'=$p(s,",",i+c)q=$zabs(d),v=$s(c>2&d:"-"_(c-1*d+a)_$s(q=1:"",1:"/"_q),c>1&'d:"*"_c,1:0) s:v'=0 $p(s,",",i,i+c-1)=a_q:a="" a
}
 

size = 189

ClassMethod Compress(As %StringAs %String
{
 i=1:1:2e6{a=$p(s,",",i),d=$p(s,",",i+1)-c=1:1{q:d*c+a'=$p(s,",",i+c)q=$zabs(d),v=$s(c>2&d:"-"_(c-1*d+a)_$s(q=1:"",1:"/"_q),c>1&'d:"*"_c,1:0) s:v'=0 $p(s,",",i,i+c-1)=a_vs
}
Vitaliy Serdtsev · May 11, 2022 go to post

(And I think you may be waiting a long time for the Encoder game to close)
The author seems to have forgotten or this no longer relevant. I'm not interested in opening code when there are no alternatives and there is no competitive spirit.

Vitaliy Serdtsev · May 11, 2022 go to post
 

size = 74

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 q $$r(a)=$$r(b)
r(x)i=65:1:90{s $li(y,i)=$l($zcvt(x,"u"),$c(i))y
}

I'm not publishing the option with size = 73 yet, to wait, maybe someone will guess how to do it or offer an ever shorter option (by analogy with Code Golf - Encoder).

UPD: I managed to reduce size to 72.

Vitaliy Serdtsev · May 10, 2022 go to post
 

Example

Class dc.golf.Anagram
{

ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
  c="a","b"{
    @c=$zstrip($zcvt(@c,"U"),"*W")
  }
  w $$$quote(a),":",$l(a)," - ",$$$quote(b),":",$l(b),!
  q $tr(a,b)=$tr(b,a)&($l(a)=$l(b))
}

}

Output (tested on IRIS 2021.2CE):

USER>##class(dc.golf.Anagram).Detector("apple""pale")
 
<UNDEFINED>zDetector+2^dc.golf.Anagram.1 *a

If I change Undefined, then there is no error, but the result is incorrect:

USER>d $system.Process.Undefined(2)
 
USER>##class(dc.golf.Anagram).Detector("apple""pale")
"apple":5 - "pale":4
0

The code works correctly if change the signature of the method (ProcedureBlock/PublicList/new), but this is a violation of the conditions of the task.

Vitaliy Serdtsev · May 4, 2022 go to post

See %ZEN.Auxiliary.jsonSQLProvider:%WriteJSONStreamFromSQL()

 

Simple example

Class dc.test Extends %Persistent
{

Property int As %Integer;

Property str As %VarString;

Property bool As %Boolean;

Property Date As %Date;

ClassMethod Test()
{
  ..%KillExtent()
  
  &sql(insert into dc.test("int",str,bool,"Date")
        select 30,'Hello Caché',0,current_date
        union
        select 303,'ăîşţâ',1,0
        union
        select null,null,null,null)
  
  
  stream=##class(%Stream.FileBinary).%New(),
    stream.Filename="c:\temp\test.json",
  
    sql="select * from dc.test",
    format="twu",
    maxRows=0

  status=##class(%ZEN.Auxiliary.jsonSQLProvider).%WriteJSONStreamFromSQL(.streamsqlformatmaxRows)  

  d:$$$ISOK(statusstream.%Save()
}

}

The contents of the file test.json (UTF8):

{
"children":[
{"ID":1,"Date":"04.05.2022","bool":0,"int":30,"str":"Hello Caché"}
,{"ID":2,"Date":"31.12.1840","bool":1,"int":303,"str":"ăîşţâ"}
,{"ID":3,"Date":"","bool":"","int":"","str":""}
]
}
Vitaliy Serdtsev · May 3, 2022 go to post

My current result: size = 94 84

 
ClassMethod Detector(
  As %String,
  As %StringAs %Boolean
{
 s:$l(a)>$l(bi=b,b=a,a=i=1:1:$l(a){b=$replace(b,$e(a,i),"",,1,1)b?." "
}
Vitaliy Serdtsev · Apr 27, 2022 go to post

I already tried option 1 with Timeformat=1 for the avg and didn't work.
Have you changed the TimeFormat at the process or system level? If at the process level, then most likely you have changed this value in one process, and are executing the query in another. Therefore, there is no effect. If at the system level, then the query should work.

To avoid uncertainty, change the definition of the field

Property PackingTimeSpent As %Time;

and execute in SMP for Display Mode

select PackingTimeSpent from MSDS_Serenity.KitlabelAssoc

The hh:mm:ss format string should be displayed.

so eg. select %external(CAST(+avg(166.38) as TIME)) didn't work for me
Two remarks:
  • this will work as intended only if you have changed the TimeFormat=1 at the system level
  • avg(166.38) - it's pointless to write like that.

you mentioned the example above and I'm not sure to which one are youi refering to with so many replies, so can you point me to which one exactly
See Time-to-String Conversionlink

Try this (does not depend on the TimeFormat value of the current locale):

select TO_CHAR(avg(PackingTimeSpent),'HH24:MI:SS'average from MSDS_Serenity.KitlabelAssoc where label='00007IT4'

PS: By the way, I noticed in your screenshots the differences in queries: somewhere you write

where label='00007IT4'
somewhere you write
where ID='00007IT4'

Is this how it should be? To avoid unnecessary questions, please do not change everytime the names of the fields in the queries. This is misleading.

Vitaliy Serdtsev · Apr 27, 2022 go to post

If the data already exists, then this is a non-trivial task, especially if inheritance or Parent/Child is present, since this will lead to a change in the storage scheme of your data.

The easiest way to do this is through an intermediate (temporary) table:
  1. create a new class with the same structure, but with a new primary key;
  2. move data from the old class into it using SQL (not the merge command);
  3. delete data/indexes in the old class, then change the primary key in it;
  4. move data from the new class to the old class, using the merge command;
  5. delete the new class with the data;
  6. rebuild the indexes if there are any.

Useful links: MERGE Persistent Objects and InterSystems IRIS SQL Introduction to Persistent Objects

If you feel insecure with Caché/IRIS, it is better to ask WRC for help.

Vitaliy Serdtsev · Apr 27, 2022 go to post

From doc:

AVG returns either NUMERIC data type values or DOUBLE data type values. If expression is data type DOUBLE, AVG returns DOUBLE; otherwise, it returns NUMERIC.

For non-DOUBLE expression values, AVG returns a double-precision floating point number.proof

The specification of the field [%Time(FORMAT=1)] plays absolutely no role in the case of an aggregate function, since AVG returns just a number (DOUBLE or NUMERIC).

Above I gave links to examples of how a number can be converted to TIME, then to STRING.

For example:

  1. if in the current locale TimeFormat = 1
    select %external(CAST(+166.38 as TIME))
  2. Important: it is necessary to convert a float number to an integer type, otherwise you will get zero.

  3. if in the current locale TimeFormat <> 1
    select TO_CHAR(166.38,'HH24:MI:SS')
Vitaliy Serdtsev · Apr 26, 2022 go to post

Try other methods/queries of this class, such as Dump*, ProcessList, ConnectionList, etc., which return the number of connections.

Vitaliy Serdtsev · Apr 26, 2022 go to post

It is very strange that the mechanism ^%SYS("CSP", "MimeFileClassify") does not work for you.

According to the sources of %CSP.StreamServer, it can be seen that all the work takes place in the FileClassify method, where ^%SYS("CSP", "MimeFileClassify") is also used.

I used ZEN on Caché and all was fine.

Can you give a simple CSP example to reproduce your situation?

Vitaliy Serdtsev · Apr 26, 2022 go to post

Try this (%Dialect):

Set sqlStatement=##class(%SQL.Statement).%New(,,"MSSQL")
 

Simple example

Class dc.test Extends %Persistent
{

Property As %Integer;

ClassMethod Test()
{
  
  ..%KillExtent()
  
  &sql(insert into dc.test(tvalues(30))
  &sql(insert into dc.test(tvalues(303))
  
  zw ^dc.testD

  !
  
  sql=2
  sql(1)="update dc.test set t=t+1 where ID=1"
  sql(2)="update dc.test set t=t+2 where ID=2"
  
  st=##class(%SQL.Statement).%New(,,"MSSQL")
  
  "SQLCODE=",st.%ExecDirect(.st,.sql).%SQLCODE,!!
  
  zw ^dc.testD
}

}

Output:

USER>##class(dc.test).Test()
^dc.testD=2
^dc.testD(1)=$lb("",30)
^dc.testD(2)=$lb("",303)
 
SQLCODE=0
 
^dc.testD=2
^dc.testD(1)=$lb("",31)
^dc.testD(2)=$lb("",305)