Kdbplus-q-programming-language

提供:Dev Guides
移動先:案内検索

Qプログラミング言語

Kdb +には、 q として知られる組み込みプログラミング言語が付属しています。 時系列分析用に拡張された標準SQLのスーパーセットが組み込まれており、標準バージョンよりも多くの利点があります。 SQLに精通している人なら、数日のうちに q を学び、自分のアドホッククエリをすばやく書くことができます。

「q」環境の開始

kdb +の使用を開始するには、 q セッションを開始する必要があります。 q セッションを開始するには3つの方法があります-

  • 実行端末で「c:/q/w32/q.exe」と入力するだけです。
  • MS-DOSコマンドターミナルを起動し、 q と入力します。
  • q.exe ファイルを「C:\ Windows \ System32」にコピーし、実行端末で「q」と入力します。

ここでは、Windowsプラットフォームで作業していると想定しています。

データ型

次の表は、サポートされているデータ型のリストを提供します-

Name Example Char Type Size
boolean 1b b 1 1
byte 0xff x 4 1
short 23h h 5 2
int 23i i 6 4
long 23j j 7 8
real 2.3e e 8 4
float 2.3f f 9 8
char “a” c 10 1
varchar `ab s 11 *
month 2003.03m m 13 4
date 2015.03.17T18:01:40.134 z 15 8
minute 08:31 u 17 4
second 08:31:53 v 18 4
time 18:03:18.521 t 19 4
enum `u$`b, where u:`a`b * 20 4

原子とリストの形成

原子は、単一のエンティティ、たとえば、単一の数字、文字、または記号です。 (異なるデータ型の)上記の表では、サポートされているすべてのデータ型はアトムです。 リストは、一連のアトムまたはリストを含む他のタイプです。

任意の型のアトムをモナドに渡す(つまり、 単一引数関数)型関数は負の値、つまり –n を返しますが、これらのアトムの単純なリストを型関数に渡すと正の値 n を返します。

例1 –アトムとリストの形成

/Note that the comments begin with a slash “/” and cause the parser
/to ignore everything up to the end of the line.

x: `mohan             /`mohan is a symbol, assigned to a variable x
type x                /let’s check the type of x
-11h                  /-ve sign, because it’s single element.

y: (`abc;`bca;`cab)   /list of three symbols, y is the variable name.

type y
11h                   /+ve sign, as it contain list of atoms (symbol).

y1: (`abc`bca`cab)    /another way of writing y, please note NO semicolon

y2: (`$”symbols may have interior blanks”)  /string to symbol conversion
y[0]                  /return `abc
y 0                   /same as y[0], also returns `abc
y 0 2                 /returns `abc`cab, same as does y[0 2]

z: (`abc; 10 20 30; (`a`b); 9.9 8.8 7.7)     /List of different types,
z 2 0                 /returns (`a`b; `abc),
z[2;0]                /return `a. first element of z[2]

x: “Hello World!”     /list of character, a string
x 4 0                 /returns “oH” i.e. 4th and 0th(first)
element