unknown data type return from KDB+ -79 - kdb

i am facing a very strange problem in KDB+. where data type returned from kdb+ server is -79. that i can't find out.
does any body know that type is it. ?

79h is type for mapped list of lists of GUID data type.
Reference: http://code.kx.com/q/ref/datatypes/
Section: Nested Type.
From page:
Nested Type:
These types are used for mapped lists of lists of the same type. The numbering is 77 + primitive type.
Guid type is 2 which gives it's nested type value=79
ex:
q)`:t1.dat set 2 2#0x0 sv 16?0xff
q) a:get `:t1.dat
q) type a
q) 79h

Related

how to match the structures in C?

In SV,
struct
{
int a;
int b;
} abc, abc1;
where the abc and abc1 are matching type but the
struct {int a; int b; } abc2; abc2 is not matching to abc1.
Why is it so, even though the members of the structures are same?
The rules in section 6.22 Type compatibility of the 1800-2017 SystemVerilog LRM explain that anonymous types can only match:
objects declared within the same declaration statement and no other
data types
In general, SystemVerilog has a strong typing policy for unpacked structs. This means the criteria for matching types is the name alone and not by looking into the layout of the structure.

The function of validate input params

Definded the method to validate input params :
`validate_paramaters{[Date;Code;CodeType;Param]
if[ not (14h=abs[type[Date]]);
[
.log.info["\tError - Exiting function - Date is not of the correct type"];
: `$"Error - Date is not of the correct type"
]
];
if[ not (11h=abs[type[Code]]);
[
.log.info["\tError - Exiting function - Code is not of the correct type"];
: `$"Error - Code is not of the correct type"
]
];
if[ not (-11h=type[CodeType]);
[
.log.info["\tError - Exiting function - CodeType is not of the correct type"];
: $"Error - CodeType is not of the correct type"
]
];
:`validated
}`
But now The CodeType`s type add more addition :
-11h=type[CodeType] `also can be` 99h=type[CodeType]
Please give me a guidance how can i validate the CodeType now
Replace your not (-11h=type[CodeType]) with not any -11 99h in type CodeType
The keyword in allows you to compare the type of CodeType with a list of numeric types. This returns a boolean list. For example:
q)CodeType:`sample`dictionary!`a`b
q)-11 99h in type CodeType
01b
The any prepended to that returns a 1b if ANY members of the list are True.
q)any -11 99h in type CodeType
1b
Finally, you seem to be throwing errors if the CodeType is NOT one of the aforementioned types, so we'll prepend this all with a not.
Alternatively to Jemma's response, you could also try a more concise method:
validate:{[d;names;types]
if[count fails:key[d] where not any each types=type each d[names];
:"error - exiting - ",("," sv string fails)," are not of correct type"];
};
This first parameter of this function is a dictionary (d) where the key is the names of the arguments and the values are their corresponding values. This argument can be passed along with the names of the variables you are querying and the types they should be. Nested lists should be used if you're looking for multiple types to conform against.
For example, here is a dictionary with valid entries.
q)d:`date`code`codetype!(.z.d;`some`code`to`test;`thetypeofmycode)
q)validate[d;`date`code`codetype;(-14;11;(-11 99h))]
q)
However, you can see this returns an error if the dictionary is updated with an invalid datatype.
q)d[`code]:"wrongtype"
q)d[`date]:.z.p
q)validate[d;`date`code`codetype;(-14;11;(-11 99h))]
"error - exiting - date,code are not of correct type"
Just note that the list of types has to be in the same order as the dictionary
To incorporate your .log.info you can adapt the above function as so:
validate:{[d;names;types]if[count fails:key[d] where not any each types=type each d key d;
.lg.info"error - exiting - ",("," sv string[fails])," are not of correct type";
:"error: ",("," sv string[fails])," - type incorrect"]}
Referring to the example above, this would return the same result but this time logging the error using .log.info also.

How does an integer store a literal (eg var x = 0)

when i write var x = 0
I know that x is an object that has properties and methods (created from Int Structure).
Where and how does x store the 0 ?
Is the 0 stored as a property of x ?
If yes, what would be the type of that property ?
If not, where is it stored ?
x is not an object, strictly speaking. "Object" is a name we give to instances of classes, not structs. x is an instance of the Int struct.
The Int structure wraps a Builtin integer type, and defines a bunch of methods you can call on it. That builtin integer literal type isn't accessible from Swift (nor is there a reason for it to be). Like all structures, instances of Int are stored on the runtime stack. They're not objects on the heap like Integer in Java, for example.
You can see the implementation details of (U)Int(8/16/32/64) here. This file uses the Generate Your Boilerplate (GYB) preprocessor created by the Swift team to generate .swift files from .swift.gyb template files.
On line 221, you can see the property _value of type Builtin.${BuiltinName}. The GYB preprocessor expands this out so that Int has a _value of type Builtin.Int, Int64 has Built.Int64, etc.

type char to type num mapping

q)type variable
returns the type num of the arguement variable.
Is there a mapping that can produce the type char from a type num or do I have to create that dictionary myself?
Ideally something like
q)typeChar 1
i
You can use .Q.t.
q).Q.t abs type `test
"s"
q).Q.t abs type 5i
"i"
Edit: Or even better just use .Q.ty
This seems to return upper case for atoms and lower case for lists.
q).Q.ty `test
"S"
q).Q.ty `test`test2
"s"
One option is to use 'key' function :
Reference: http://code.kx.com/q/ref/metadata/#key
Wiki says: Given a simple list, returns the name of the type as a symbol:
So you can make function like:
q) tyeInChar:{key x,()}
q) typeInChar 1i // output `int
q) typeInChar "s" //output `char

Operating on internal tables with header line

I have a question about internal tables' header line.
I assigned some values into in_table1 and then try to add a record with APPEND command into in_table2 in the following block of code.
But I cannot see the record that I have appended into in_table2.
Is this because of the header line of in_table2?
If yes, how can I see the records anyway?
*&---------------------------------------------------------------------*
*& Report ZTEST_LOOP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_STRUCT_DATA_TYPE.
***** define structure data types
TYPES: BEGIN OF adres_bilgileri, " this is a struct with a set of types
sokak type c length 30,
cadde type c length 30,
sehir type c length 15,
ev_no type n length 4,
end of adres_bilgileri.
types: BEGIN OF personel_bilgileri,
ad type c LENGTH 20,
soyad type c LENGTH 20,
tel_no type n LENGTH 12,
adres TYPE adres_bilgileri," ********************!!!!!!!!!!!!!!!!!!!!!!
END OF personel_bilgileri.
TYPES personel_bilgi_tablosu TYPE STANDARD TABLE OF personel_bilgileri WITH key TABLE_LINE.
data: in_table1 type personel_bilgileri,
in_table2 type personel_bilgi_tablosu WITH HEADER LINE.
"adres1 type adres_bilgileri.
in_table1-ad = 'Latife'.
in_table1-soyad = 'A'.
in_table1-adres-sokak = 'Hasanpaşa'. """"""""""""adresten sokak bilgisine geçiş
in_table1-adres-ev_no = 10.
append in_table1 to in_table2.
WRITE / : 'Records in in_table2:', in_table2.
First of all, you should not use internal tables with header anymore.
Second of all, if you really have to do it, here is some solution.
The header in_table2 is of course empty in your case. You have to loop through the table to print it out. For example like this.
LOOP AT in_table2. "here in_table2 means table (an internal table)
WRITE / in_table2. "here in_table2 means the header of the table (a structure)
ENDLOOP.
Internal tables with headers should not be used exactly because of this confusion. Looks like you got confused exactly in such way. The meaning of in_table2 is ambiguous and depends on the context.
Better use field symbols for looping and appending.
FIELD-SYMBOLS: <fs_for_loop> LIKE LINE OF in_table2[].
LOOP AT in_table2[] ASSIGNING <fs_for_loop>.
WRITE / <fs_for_loop>.
ENDLOOP.