Skip to content

Commit a630bc9

Browse files
authored
Merge pull request #335 from sshanks-kx/refactor
refactor
2 parents 92aa071 + b8fe6ea commit a630bc9

File tree

14 files changed

+222
-127
lines changed

14 files changed

+222
-127
lines changed

docs/basics/cmdline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ and with `-q`
307307
Replicate from `:host:port`.
308308

309309
:fontawesome-solid-book-open:
310-
[`\r` system command](syscmds.md#r-replication-master)
310+
[`\r` system command](syscmds.md#r-replication-primary)
311311

312312

313313
## `-s` (secondary threads)

docs/basics/comparison.md

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,102 @@ q)(1 + 1e-13) = 1
7373

7474
## Temporal values
7575

76+
Below is a matrix of the [type](datatypes.md) used when the temporal types differ in a comparison (note: you may need to scroll to the right to view the full table):
77+
78+
| comparison types | **timestamp** | **month** | **date** | **datetime** | **timespan** | **minute** | **second** | **time** |
79+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
80+
| **timestamp** | _timestamp_ | _timestamp_ | _timestamp_ | _timestamp_ | _timespan_ | _minute_ | _second_ | _time_ |
81+
| **month** | _timestamp_ | _month_ | _date_ | _not supported_ | _not supported_ | _not supported_ |_not supported_ | _not supported_ |
82+
| **date** | _timestamp_ | _date_ | _date_ | _datetime_ | _not supported_ | _not supported_ |_not supported_ | _not supported_ |
83+
| **datetime** | _timestamp_ | _not supported_ | _datetime_ | _datetime_ | _timespan_ | _minute_ | _second_ | _time_ |
84+
| **timespan** | _timespan_ | _not supported_ | _not supported_ | _timespan_ | _timespan_ | _timespan_ | _timespan_ | _timespan_ |
85+
| **minute** | _minute_ | _not supported_ | _not supported_ | _minute_ | _timespan_ | _minute_ | _second_ | _time_ |
86+
| **second** | _second_ | _not supported_ | _not supported_ | _second_ | _timespan_ | _second_ | _second_ | _time_ |
87+
| **time** | _time_ | _not supported_ | _not supported_ | _time_ | _timespan_ | _time_ | _time_ | _time_ |
88+
89+
For example
90+
```q
91+
q)20:00:00.000603286 within 13:30 20:00t / comparison of timespan and time, time converted to timespan values 0D13:30:00.000000000 0D20:00:00.000000000
92+
0b
93+
q)2024.10.07D20:00:00.000603286 within 13:30 20:00t / comparison of timestamp and time, timestamp converted to time value 20:00:00.000
94+
1b
95+
```
96+
7697
Particularly notice the comparison of ordinal with cardinal datatypes, such as timestamps with minutes.
7798

7899
```q
79100
q)times: 09:15:37 09:29:01 09:29:15 09:29:15 09:30:01 09:35:27
80-
q)spans:`timespan$times / timespans: cardinal
81-
q)stamps:.z.D+times / timestamps: ordinal
82-
q)t:09:29 / minute: cardinal
101+
q)tab:([] timeSpan:`timespan$times; timeStamp:.z.D+times)
102+
q)meta tab
103+
c | t f a
104+
---------| -----
105+
timeSpan | n
106+
timeStamp| p
83107
```
84108

85-
When comparing ordinals with cardinals, ordinal is converted to the cardinal type first: `stamps=t` is equivalent to ``(`minute$stamps)=t`` and thus
109+
When comparing `timestamp` with `minute`, the timestamps are converted to minutes such that `` `minute$2024.11.01D09:29:15.000000000 `` becomes `09:29` and therefore doesn't appear in the output:
86110

87111
```q
88-
q)(stamps<t;stamps=t;stamps>t)
89-
100000b
112+
q)select from tab where timeStamp>09:29 / comparing timestamp with minute
113+
timeSpan timeStamp
114+
--------------------------------------------------
115+
0D09:30:01.000000000 2016.09.06D09:30:01.000000000
116+
0D09:35:27.000000000 2016.09.06D09:35:27.000000000
117+
```
118+
119+
When comparing `timespan` with `minute`, the minute is converted to timespan such that `09:29` becomes `0D09:29:00.000000000` for the following comparison:
120+
121+
```q
122+
q)select from tab where timeSpan>09:29 / comparing timespan with minute
123+
timeSpan timeStamp
124+
--------------------------------------------------
125+
0D09:29:01.000000000 2016.09.06D09:29:01.000000000
126+
0D09:29:15.000000000 2016.09.06D09:29:15.000000000
127+
0D09:29:15.000000000 2016.09.06D09:29:15.000000000
128+
0D09:30:01.000000000 2016.09.06D09:30:01.000000000
129+
0D09:35:27.000000000 2016.09.06D09:35:27.000000000
130+
```
131+
132+
Therefore, when comparing ordinals with cardinals (i.e. timestamp with minute), ordinal is converted to the cardinal type first.
133+
134+
For example:
135+
```q
136+
q)select from tab where timeStamp=09:29
137+
timeSpan timeStamp
138+
--------------------------------------------------
139+
0D09:29:01.000000000 2016.09.06D09:29:01.000000000
140+
0D09:29:15.000000000 2016.09.06D09:29:15.000000000
141+
0D09:29:15.000000000 2016.09.06D09:29:15.000000000
142+
143+
q)tab.timeStamp=09:29
90144
011100b
91-
000011b
92-
q)(spans<t;spans=t;spans>t)
145+
```
146+
147+
is equivalent to
148+
149+
```q
150+
q)(`minute$tab.timeStamp)=09:29
151+
011100b
152+
```
153+
and thus
154+
```q
155+
q)tab.timeStamp<09:29
93156
100000b
94-
000000b
95-
011111b
157+
q)tab.timeStamp>09:29
158+
000011b
96159
```
97160

98-
:fontawesome-solid-graduation-cap:
99-
[Comparing temporals](../kb/temporal-data.md#comparing-temporals)
100-
<br>
101161
:fontawesome-solid-street-view:
102162
_Q for Mortals_
103163
[§4.9.1 Temporal Comparison](/q4m3/4_Operators/#491-temporal-comparison)
104164

165+
## Floating point
166+
167+
The comparison of floating-point types are discussed in [`comparison tolerance`](precision.md#comparison-tolerance).
105168

106169
## Different types
107170

108-
The comparison operators also work on text values (characters, symbols) – not always intuitively.
171+
The comparison operators also work on text values (characters, symbols).
109172

110173
```q
111174
q)"0" < ("4"; "f"; "F"; 4) / characters are treated as their numeric value
@@ -141,7 +204,6 @@ q)n < neg inf
141204
11111b
142205
```
143206

144-
145207
## Infinities
146208

147209
Infinities of different type are ordered by their width.
@@ -178,9 +240,6 @@ Keyword [`differ`](../ref/differ.md) is a uniform unary function that returns a
178240
[Match](../ref/match.md) (`~`) compares its arguments and returns a boolean atom to say whether they are the same.
179241

180242

181-
:fontawesome-solid-book:
182-
[Comparison tolerance](precision.md#comparison-tolerance)
183-
<br>
184243
:fontawesome-solid-street-view:
185244
_Q for Mortals_
186245
[§4.3.3 Order](/q4m3/4_Operators/#433-order)

docs/basics/precision.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords: comparison, float, precision, tolerance
1010

1111
## Float precision
1212

13-
Precision of floats is a tricky issue since floats (_doubles_ in other languages) are actually binary rational approximations to real numbers. Whenever you are concerned with precision, set `\P 0` before doing anything else, so that you can see whats really going on.
13+
Precision of floats is a complex issue because floats (known as _doubles_ in other programming languages) are actually binary rational approximations of real numbers. If you are concerned with precision, make sure to set [`\P 0`](syscmds.md#p-precision) before proceeding with anything else. This helps you understand what's really happening with your data.
1414

1515
Due to the finite accuracy of the binary representation of floating-point numbers, the last decimal digit of a float is not reliable. This is not peculiar to kdb+.
1616

@@ -22,7 +22,7 @@ q)1%3
2222

2323
Efficient algorithms for complex calculations such as log and sine introduce imprecision. Moreover, even basic calculations raise issues of rounding. The IEEE floating-point spec addresses many such issues, but the topic is complex.
2424

25-
Q takes this into account in its implementation of the equality operator `=`, which should actually be read as “tolerantly equal.” Roughly speaking, this means that the difference is relatively small compared to some acceptable representation error. This makes the following hold:
25+
Q takes this into account in its implementation of the equality operator [`=`](comparison.md), which should actually be read as “tolerantly equal.” Roughly speaking, this means that the difference is relatively small compared to some acceptable representation error. This makes the following hold:
2626

2727
```q
2828
q)r7:1%7
@@ -102,7 +102,7 @@ The l64 builds of kdb+ now have a faster SIMD [`sum`](../ref/sum.md) implementat
102102

103103
Consider the task of calculating the sum of `1e-10*til 10000000`.
104104

105-
The SIMD code is equivalent to the following (`\P 0`):
105+
The SIMD code is equivalent to the following ([`\P 0`](syscmds.md#p-precision)):
106106

107107
```q
108108
q){x+y}over{x+y}over 0N 8#1e-10*til 10000000
@@ -280,4 +280,4 @@ These do not use comparison tolerance, and are therefore appropriate for databas
280280

281281
:fontawesome-regular-hand-point-right:
282282
[Comparison](comparison.md),
283-
[Match](../ref/match.md), [`differ`](../ref/differ.md)
283+
[Match](../ref/match.md), [`differ`](../ref/differ.md)

docs/basics/syscmds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ keywords: command, kdb+, q, system
2525
[\o offset from UTC](#o-offset-from-utc) [\\_ hide q code](#_-hide-q-code)
2626
[\p listening port](#p-listening-port) [\\ terminate](#terminate)
2727
[\P precision](#p-precision) [\\ toggle q/k](#toggle-qk)
28-
[\r replication master](#r-replication-primary) [\\\\ quit](#quit)
28+
[\r replication primary](#r-replication-primary) [\\\\ quit](#quit)
2929
[\r rename](#r-rename)
3030
</div>
3131

docs/database/mdb-odbc.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@ date: November 2020
66
# :fontawesome-brands-windows: Access a table from an MDB file via ODBC
77

88

9+
Install the [ODBC client driver for kdb+](../interfaces/q-client-for-odbc.md).
10+
Install Microsoft ODBC driver for Microsoft Access.
911

10-
From Windows, load `odbc.k` into your q session, and then load the MDB file.
12+
Using the driver installed, a MDB file can be opened using the following example command:
1113

12-
```powershell
13-
C:>q w32\odbc.k
14-
```
1514

1615
```q
17-
q)h: .odbc.load `mydb.mdb
16+
q)h:.odbc.open "driver=Microsoft Access Driver (*.mdb, *.accdb);dbq=C:\\mydb.mdb"
1817
```
1918

20-
This loads the entire database, which may consist of several tables. Use `.odbc.tables` to list the tables.
19+
!!! note "The name of the driver may differ between versions. The command above should be altered to reflect the driver name installed."
20+
21+
Use [`.odbc.tables`](../interfaces/q-client-for-odbc.md#tables) to list the tables.
2122

2223
```q
2324
q).odbc.tables h
2425
`aa`bb`cc`dd`ii`nn
2526
```
2627

27-
Use `.odbc.eval` to evaluate SQL commands via ODBC.
28+
Use [`.odbc.eval`](../interfaces/q-client-for-odbc.md#eval) to evaluate SQL commands via ODBC.
2829

2930
```q
3031
q).odbc.eval[h;"select * from aa"]
3132
```
3233

33-
---
34-
:fontawesome-solid-handshake:
35-
[Q driver for ODBC3](../interfaces/q-server-for-odbc3.md)
34+
An alternative to querying through SQL is to load the entire database into kdb+ via the [.odbc.load](../interfaces/q-client-for-odbc.md#load) command, where the data can then be queried using kdb+ directly.

docs/interfaces/capiref.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ Increment an object‘s reference count.
885885
V sd0(I d)
886886
```
887887

888-
Remove the callback on `d` and call `kclose`.
888+
Remove the callback on `d` and call `kclose`. Should only be called from main thread.
889889

890890
Shared library only.
891891

@@ -896,9 +896,9 @@ Shared library only.
896896
V sd0x(I d, I f)
897897
```
898898

899-
Remove the callback on `d` and call `kclose` on `d` if `f` is 1.
899+
Remove the callback on `d` and call `kclose` on `d` if `f` is 1. Should only be called from main thread.
900900

901-
Shared library only. Since V3.0 2013.04.04.
901+
Shared library only. Ssince V3.0 2013.04.04.
902902

903903

904904
### `sd1` (set function on loop)
@@ -907,19 +907,21 @@ Shared library only. Since V3.0 2013.04.04.
907907
K sd1(I d, f)
908908
```
909909

910-
Put the function `K f(I d){…}` on the q main event loop given a socket `d`.
910+
Put the function `K f(I d){…}` on the q main event loop given a socket `d`. Should only be called from main thread.
911911

912912
If `d` is negative, the socket is switched to non-blocking.
913913

914-
The function `f` should return `NULL` or a pointer to a K object, and its reference count will be decremented.
915-
(It is the return value of `f` that will be `r0`’d – and only if not null.)
914+
The function `f` should return `NULL` or a pointer to a K object.
915+
If the return value of `f` is a pointer to a K object, its reference count is decremented i.e. passed to [`r0`](#r0-decrement-refcount).
916916

917-
Shared library only.
918917

919-
On success, returns int K object containing `d`. On error, `NULL` is returned, `d` is closed.
918+
On success, `sd1` returns a K object of type integer, containing `d`. On error, `NULL` is returned and `d` is closed.
919+
920920

921921
Since 4.1t 2023.09.15, sd1 no longer imposes a limit of 1023 on the value of the descriptor submitted.
922922

923+
Shared library only.
924+
923925
:fontawesome-regular-hand-point-right:
924926
[Callbacks](c-client-for-q.md#callbacks)
925927

0 commit comments

Comments
 (0)