Progress 4GL: Cannot READ-JSON the JSON that was written - json

I am having a problem with Progress READ-JSON where it is not accepting the JSON that was output by WRITE-JSON. We are using TRACKING-CHANGES with a dataset with a nested data-relation.
OUTPUT TO "debug.txt".
DEFINE VARIABLE lcString AS LONGCHAR NO-UNDO.
DEFINE VARIABLE hdsBox AS HANDLE NO-UNDO.
DEFINE VARIABLE lOk AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE ttEmployee NO-UNDO
BEFORE-TABLE ttEmployeeBefore
FIELD eid AS INTEGER
FIELD empname AS CHAR.
DEFINE TEMP-TABLE ttBox NO-UNDO
BEFORE-TABLE ttBoxBefore
FIELD eid AS INTEGER SERIALIZE-HIDDEN
FIELD boxid AS INTEGER
FIELD boxdesc AS CHAR.
DEFINE DATASET dsBox FOR ttEmployee, ttBox
DATA-RELATION relat1 FOR ttEmployee, ttBox RELATION-FIELDS (ttEmployee.eid, ttBox.eid) NESTED.
CREATE ttEmployee.
CREATE ttBox.
ASSIGN ttEmployee.eid = 1
ttEmployee.empname = "Ian"
ttBox.eid = 1
ttBox.boxid = 10
ttBox.boxdesc = "Ians box".
hdsBox = DATASET dsBox:HANDLE.
ASSIGN TEMP-TABLE ttEmployee:TRACKING-CHANGES = YES
TEMP-TABLE ttBox:TRACKING-CHANGES = YES.
CREATE ttBox.
ASSIGN ttBox.eid = 1
ttBox.boxid = 11
ttBox.boxdesc = "Stewarts box"
/*ttEmployee.empname = "Stewart"*/ .
ASSIGN lOk = hdsBox:WRITE-JSON("LONGCHAR", lcString,FALSE , "UTF-8", FALSE, FALSE, TRUE).
ASSIGN TEMP-TABLE ttEmployee:TRACKING-CHANGES = NO
TEMP-TABLE ttBox:TRACKING-CHANGES = NO.
MESSAGE lOk ERROR-STATUS:GET-MESSAGE(1) SKIP.
MESSAGE STRING(lcString) SKIP.
ASSIGN lOk = hdsBox:READ-JSON("LONGCHAR":U, lcString, "EMPTY":U) NO-ERROR.
MESSAGE lOk ERROR-STATUS:GET-MESSAGE(1) SKIP.
This example generates the following output:
yes
{"dsBox":{"prods:hasChanges":true,"ttEmployee":[{"eid":1,"empname":"Ian","ttBox":[{"boxid":10,"boxdesc":"Ians box"},{"prods:id":"ttBox96513","prods:rowState":"created","boxid":11,"boxdesc":"Stewarts box"}]}],"prods:before":{}}}
no Error parsing JSON: expected string, but found bracket. (15358)
If I take out the comment on line 35, then it works, which leads me to believe it is a Progress bug.
I am using OpenEdge 11.4.

This is a Progress bug. To fix, I need to insert a meaningless field into the before-table of the JSON.
"prods:before":{"Progress11.4bug":"Need this string or Progress will barf"}
Progress doesn't like the before-table to be empty for some reason.

Related

XGboost considers numeric variables as categorical variables because there are too few unique values

I have built an XGboost model and trying to write a custom function such as:
cols_when_model_builds = model.get_booster().feature_names
def get_prediction(parameter_1, parameter_2, parameter_3):
all_columns = ["parameter_1", "parameter_2", "parameter_3"]
lst = [parameter_1, parameter_2, parameter_3]
df = pd.DataFrame([lst], columns=all_columns)
X = pd.get_dummies(df, columns=["parameter_1"], drop_first=False)
X2 = pd.DataFrame(columns = cols_when_model_builds)
X = X.reindex(labels=X2.columns,axis=1)
result = model.predict(X)
Thus, "parameter_3" is a categorical feature and the other two parameters are integer features (numeric). However, when I pass a value to "parameter_3" it return an error:
ValueError: DataFrame.dtypes for data must be int, float, bool or category. When
categorical type is supplied, DMatrix parameter `enable_categorical` must
be set to `True`. Invalid columns:"parameter_2"
It should be noted that the code doesn't have problems with the "parameter_1" even though it is numeric as well
Setting "enable_categorical" won't work because the trouble making parameter is not categorical.

Function parameter names in Kotlin

I saw in some Kotlin samples the next syntax where the name of the parameter is set before the value being passed:
LoginResult(success = LoggedInUserView(displayName = result.data.displayName))
What is above the difference from the next syntax? Is it only visual or has some type of purpose?
LoginResult(LoggedInUserView(result.data.displayName))
According to the Kotlin Documentation:
When calling a function, you can name one or more of its arguments. This may be helpful when a function has a large number of arguments, and it's difficult to associate a value with an argument, especially if it's a boolean or null value.
When you use named arguments in a function call, you can freely change the order they are listed in, and if you want to use their default values you can just leave them out altogether.
So essentially, they are helpful when you have a lot of parameters to a function. For example, instead of:
doSomething(true, true, true)
We can name these parameters, for clarity:
doSomething(
first = true,
second = true,
third = true
)
The compiled code is identical, this is for developer clarity only.
The other use case is so you can mix up the order, if you'd like:
doSomething(
third = true,
first = false,
second = false
)
Again, the code that gets generated works the same way, this is also for developer clarity.
yes, that only visualize your parameters value.
you can use it or not, and it will not make a trouble.
and it's special
see my example of my data class
data class Movie(
var title: String? = null,
var poster: Int? = 0,
var originalLang: String? = null
)
then you can easily put the constructor without see the stream
like :
val movie = Movie(poster = 9, originalLang = "en", title = "Overlord")

mySql JSON string field returns encoded

First week having to deal with a MYSQL database and JSON field types and I cannot seem to figure out why values are encoded automatically and then returned in encoded format.
Given the following SQL
-- create a multiline string with a tab example
SET #str ="Line One
Line 2 Tabbed out
Line 3";
-- encode it
SET #j = JSON_OBJECT("str", #str);
-- extract the value by name
SET #strOut = JSON_EXTRACT(#J, "$.str");
-- show the object and attribute value.
SELECT #j, #strOut;
You end up with what appears to be a full formed JSON object with a single attribute encoded.
#j = {"str": "Line One\n\tLine 2\tTabbed out\n\tLine 3"}
but using JSON_EXTRACT to get the attribute value I get the encoded version including outer quotes.
#strOut = "Line One\n\tLine 2\tTabbed out\n\tLine 3"
I would expect to get my original string with the \n \t all unescaped to the original values and no outer quotes. as such
Line One
Line 2 Tabbed out
Line 3
I can't seem to find any JSON_DECODE or JSON_UNESCAPE or similar functions.
I did find a JSON_ESCAPE() function but that appears to be used to manually build a JSON object structure in a string.
What am I missing to extract the values to the original format?
I like to use handy operator ->> for this.
It was introduced in MySQL 5.7.13, and basically combines JSON_EXTRACT() and JSON_UNQUOTE():
SET #strOut = #J ->> '$.str';
You are looking for the JSON_UNQUOTE function
SET #strOut = JSON_UNQUOTE( JSON_EXTRACT(#J, "$.str") );
The result of JSON_EXTRACT() is intentionally a JSON document, not a string.
A JSON document may be:
An object enclosed in { }
An array enclosed in [ ]
A scalar string value enclosed in " "
A scalar number or boolean value
A null — but this is not an SQL NULL, it's a JSON null. This leads to confusing cases because you can extract a JSON field whose JSON value is null, and yet in an SQL expression, this fails IS NULL tests, and it also fails to be equal to an SQL string 'null'. Because it's a JSON type, not a scalar type.

Order of fields in a type for FileHelpers

I'm reading a simple CSV file with Filehelpers - the file is just a key, value pair. (string, int64)
The f# type I've written for this is:
type MapVal (key:string, value:int64) =
new()= MapVal("",0L)
member x.Key = key
member x.Value = value
I'm missing something elementary here, but FileHelpers always assumes the order of fields to be the reverse of what I've specified - as in Value, Key.
let dfe = new DelimitedFileEngine(typeof<MapVal>)
let recs = dfe.ReadFile(#"D:\e.dat")
recs |> Seq.length
What am I missing here?
The order of primary constructor parameters doesn't necessarily determine the order that fields occur within a type (in fact, depending on how the parameters are used, they may not even result in a field being generated). The fact that FileHelpers doesn't provide a way to use properties instead of fields is unforunate, in my opinion. If you want better control over the physical layout of the class, you'll need to declare the fields explicitly:
type MapVal =
val mutable key : string
val mutable value : int64
new() = { key = ""; value = 0L }
new(k, v) = { key = k; value = v }
member x.Key = x.key
member x.Value = x.value
The library uses the order of the field in the declaration, but looks like that F# words different, in the last the last stable version of the library you can use the [FieldOrder(1)] attribute to provide the order of the fields.
http://teamcity.codebetter.com/viewLog.html?buildId=lastSuccessful&buildTypeId=bt66&tab=artifacts&guest=1
Cheers

Why is this DMAX not working?

I have the following:
Textfield called: WoNr
Table column called: Workorder
= DMax("[WoNr]","[Workorder]","[Workorder]") + 1
In the text field named WoNr I have entered the code above, I get an error.
Why is this?
Why are you using "[Workorder]" as the criterion (i.e., the last parameter)? Try the following:
= DMax("WoNr", "Workorder")
If this works, continue reading.
Now about the "+ 1" thing. You say that WoNr is a text field (rather than a numeric field). So, what do you want to get? Do you want to append "1" to the string (WoNr = "D1" => Result = "D11") or is WoNr actually a numeric value and you want to add 1? In any case, you should make your intention clear. For string concatenation, use &:
= DMax("WoNr", "Workorder") & "1"
for arithmetic operations, convert your text into an appropriate numeric data type first:
= CLng(DMax("WoNr", "Workorder")) + 1