Fundamentals Cpastone 1.7

Hello! I tried the following lines of code for loading the data from the .csv file into the “messages” table. I checked the data type which needs to be loaded by using the meta-command, and I looked over the videos and tutorials as well.

Nevertheless, I do not understand what is wrong (screenshot attached).

Hi  !

The cell above exercise 1.7 declared the file path as a variable called csvPath - this can be used instead of typing out the file path again. If you edit your code to replace the file path with:

0:hsym `$csvPath;

It should work fine.

Let me know if this works!

Megan

Thank you very much! It works!

Hi Megan, when I try this, the trade_id column becomes truncated up till 9 (see image)? Any ideas why this is not working? I have tried 

count messagestrade_id // returns: 500 // but if i do 20#messagestrade_id // returns: "123456789 "

 

Thank you. 

Hi ,

Above I had answered that you only need to change the file path as this will help with passing the exercise 1 tests. However I was wrong.

If you check the trade table (screenshot below) you’ll see that trade_id is a string and the question states exch_id needs to also be read in as a string. Do this we use this character - *.

Once you read in the csv using this correct syntax, the commands you sent above should run as normal.

Thanks,

Megan

Hi Megan, thanks for the reply, 

 

Ok, now that’s sorted, I’m still getting an fail for 2.3 where I’m using

 

show messages: update broker_id: extractBrokerId each string exch_message from messages

 

with my extractBrokerId function as

 

extractBrokerId: { $[“CME” ~ 3#x; “J”$-3#x; “J”$-3#7$x] }

I had originally thought it was the messages format issue above, can you spot where I have gone wrong? Many thanks. 

C

Hi ,

Try removing the ‘string’ before exch_message when updating the messages table.

Since the exch_message column is already of type string, by putting the keyword string before a string it will separate each letter/number hence making it the incorrect format. 

Examples of this provided below - the first image is with the keyword present and the second one is with it removed.

If you have any questions please let me know,

Megan 

 

Hi Megan, 

When I remove the ‘string’ part, I get a mismatched type error. I have attached screenshots of the code again for clarity. Thanks for your help. 

Best, C 

 

Few suggestions: -

  1. I don’t know why you are assigning the result in else part to a var “b”?

  2. There is no need to hard code with the number of strings, you can write it as: -

func:{partstr:"-"vs x;$[“CME” like first partstr;“J”$last partstr;“J”$partstr 1]}

However, your code works for me: -

func:{$[“CME” ~ 3#x; “J”$-3#x; b:“J”$-3#7$x]}

q)update broker_id:func each exch_message from tab
exch_id exch_message broker_id

7 “NFB-703-GPHJOEC” 703
3 “AGP-705-BJINEED” 705
3 “FAE-703-LFMPBBF” 703
6 “CME-KECFIJG-701” 701
8 “CME-HDMFHNL-701” 701
2 “CME-AOMIHCE-702” 702
3 “CIG-705-EPJPOAC” 705
8 “CME-KONECAJ-702” 702
9 “KLI-708-MCIOGEF” 708
0 “CME-BNJBDMB-706” 706

“Mismatch” error generally means that the columns are of different sizes. Can you check the count of each column that is finally being prepared?

 

Hi kdbguru, 

(sorry the ‘b’ was a typo in the function). 

I have tried your code and it still has a mismatched types error. My table looks fine but does not pass the end-of-section test for ‘messages in correct format’. Let me put all me code regarding messages:

1.  Load from csv. 

messages: (“*S”; enlist csv) 0: hsym `$csvPath;

which looks like

trade_id exch_message ---------------------------------- ,“1” CME-KO20200720C55-706 ,“2” CME-TSLA20201120C1800-709 ,“3” CME-TSLA20210120P1500-709 ,“4” ISE-700-TSLA20210120C1800 ,“5” ISE-701-TSLA20201120C1700 ,“6” ISE-705-TSLA20201120P1600

 

  1. Define function: 

extractBrokerId :{partstr:"-"vs x;$[“CME” like first partstr;“J”$last partstr;“J”$partstr 1]}

3.  

show messages: update broker_id:extractBrokerId each exch_message from messages

which returns a mismatched error type.  This goes away if I put ‘each string exch_message’

which returns the correct table but with ‘broker_id’ in short datatype. I have then proceeded to convert the column into a long using 

messages: update trade_id: “J”$trade_id from messages

 Now the table looks perfect, but it still doesn’t pass the test. 

Any help is appreciated! Thanks! 

-C

 

Hi kdbguru, 

(sorry the ‘b’ was a typo in the function). 

I have tried your code and it still has a mismatched types error. My table looks fine but does not pass the end-of-section test for ‘messages in correct format’. Let me put all me code regarding messages:

1.  Load from csv. 

messages: (“*S”; enlist csv) 0: hsym `$csvPath;

which looks like

trade_id exch_message ---------------------------------- ,“1” CME-KO20200720C55-706 ,“2” CME-TSLA20201120C1800-709 ,“3” CME-TSLA20210120P1500-709 ,“4” ISE-700-TSLA20210120C1800 ,“5” ISE-701-TSLA20201120C1700 ,“6” ISE-705-TSLA20201120P1600

 

  1. Define function: 

extractBrokerId :{partstr:"-"vs x;$[“CME” like first partstr;“J”$last partstr;“J”$partstr 1]}

3.  

show messages: update broker_id:extractBrokerId each exch_message from messages

which returns a mismatched error type.  This goes away if I put ‘each string exch_message’

which returns the correct table but with ‘broker_id’ in short datatype. I have then proceeded to convert the column into a long using 

messages: update trade_id: “J”$trade_id from messages

 Now the table looks perfect, but it still doesn’t pass the test. 

Any help is appreciated! Thanks! 

-C