1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>4.3. Various data types — Groonga v10.1.1-31-g1e46ba6 documentation</title>
<link rel="stylesheet" href="../_static/groonga.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="4.4. Various search conditions" href="search.html" />
<link rel="prev" title="4.2. Remote access" href="network.html" />
</head><body>
<div class="header">
<h1 class="title">
<a id="top-link" href="../index.html">
<span class="project">groonga</span>
<span class="separator">-</span>
<span class="description">An open-source fulltext search engine and column store.</span>
</a>
</h1>
<div class="other-language-links">
<ul>
<li><a href="../../../ja/html/tutorial/data.html">日本語</a></li>
</ul>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="search.html" title="4.4. Various search conditions"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="network.html" title="4.2. Remote access"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../tutorial.html" accesskey="U"><span class="section-number">4. </span>Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4.3. </span>Various data types</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="various-data-types">
<h1><span class="section-number">4.3. </span>Various data types<a class="headerlink" href="#various-data-types" title="Permalink to this headline">¶</a></h1>
<p>Groonga is a full text search engine but also serves as a column-oriented data store. Groonga supports various data types, such as numeric types, string types, date and time type, longitude and latitude types, etc. This tutorial shows a list of data types and explains how to use them.</p>
<div class="section" id="overview">
<h2><span class="section-number">4.3.1. </span>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>The basic data types of Groonga are roughly divided into 5 groups — boolean type, numeric types, string types, date/time type and longitude/latitude types. The numeric types are further divided according to whether integer or floating point number, signed or unsigned and the number of bits allocated to each integer. The string types are further divided according to the maximum length. The longitude/latitude types are further divided according to the geographic coordinate system. For more details, see <a class="reference internal" href="../reference/types.html"><span class="doc">Data types</span></a>.</p>
<p>In addition, Groonga supports reference types and vector types. Reference types are designed for accessing other tables. Vector types are designed for storing a variable number of values in one element.</p>
<p>First, let’s create a table for this tutorial.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create --name ToyBox --flags TABLE_HASH_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
</div>
<div class="section" id="boolean-type">
<h2><span class="section-number">4.3.2. </span>Boolean type<a class="headerlink" href="#boolean-type" title="Permalink to this headline">¶</a></h2>
<p>The boolean type is used to store true or false. To create a boolean type column, specify Bool to the <cite>type</cite> parameter of <a class="reference internal" href="../reference/commands/column_create.html"><span class="doc">column_create</span></a> command. The default value of the boolean type is false.</p>
<p>The following example creates a boolean type column and adds three records. Note that the third record has the default value because no value is specified.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table ToyBox --name is_animal --type Bool
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{"_key":"Monkey","is_animal":true}
{"_key":"Flower","is_animal":false}
{"_key":"Block"}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
select --table ToyBox --output_columns _key,is_animal
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 3
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "is_animal",
# "Bool"
# ]
# ],
# [
# "Monkey",
# true
# ],
# [
# "Flower",
# false
# ],
# [
# "Block",
# false
# ]
# ]
# ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="numeric-types">
<h2><span class="section-number">4.3.3. </span>Numeric types<a class="headerlink" href="#numeric-types" title="Permalink to this headline">¶</a></h2>
<p>The numeric types are divided into integer types and a floating point number type. The integer types are further divided into the signed integer types and unsigned integer types. In addition, you can choose the number of bits allocated to each integer. For more details, see <a class="reference internal" href="../reference/types.html"><span class="doc">Data types</span></a>. The default value of the numeric types is 0.</p>
<p>The following example creates an Int8 column and a Float column, and then updates existing records. The <a class="reference internal" href="../reference/commands/load.html"><span class="doc">load</span></a> command updates the weight column as expected. On the other hand, the price column values are different from the specified values because 15.9 is not an integer and 200 is too large. 15.9 is converted to 15 by removing the fractional part. 200 causes an overflow and the result becomes -56. Note that the result of an overflow/underflow is undefined.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table ToyBox --name price --type Int8
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table ToyBox --name weight --type Float
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{"_key":"Monkey","price":15.9}
{"_key":"Flower","price":200,"weight":0.13}
{"_key":"Block","weight":25.7}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
select --table ToyBox --output_columns _key,price,weight
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 3
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "price",
# "Int8"
# ],
# [
# "weight",
# "Float"
# ]
# ],
# [
# "Monkey",
# 15,
# 0.0
# ],
# [
# "Flower",
# -56,
# 0.13
# ],
# [
# "Block",
# 0,
# 25.7
# ]
# ]
# ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="string-types">
<h2><span class="section-number">4.3.4. </span>String types<a class="headerlink" href="#string-types" title="Permalink to this headline">¶</a></h2>
<p>The string types are divided according to the maximum length. For more details, see <a class="reference internal" href="../reference/types.html"><span class="doc">Data types</span></a>. The default value is the zero-length string.</p>
<p>The following example creates a <code class="docutils literal notranslate"><span class="pre">ShortText</span></code> column and updates
existing records. The third record (<code class="docutils literal notranslate"><span class="pre">"Block"</span></code> key record) has the
default value (zero-length string) because it’s not updated.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table ToyBox --name name --type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{"_key":"Monkey","name":"Grease"}
{"_key":"Flower","name":"Rose"}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,name
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 3
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "name",
# "ShortText"
# ]
# ],
# [
# "Monkey",
# "Grease"
# ],
# [
# "Flower",
# "Rose"
# ],
# [
# "Block",
# ""
# ]
# ]
# ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="date-and-time-type">
<h2><span class="section-number">4.3.5. </span>Date and time type<a class="headerlink" href="#date-and-time-type" title="Permalink to this headline">¶</a></h2>
<p>The date and time type of Groonga is Time. Actually, a Time column stores a date and time as the number of microseconds since the Epoch, 1970-01-01 00:00:00. A Time value can represent a date and time before the Epoch because the actual data type is a signed integer. Note that <a class="reference internal" href="../reference/commands/load.html"><span class="doc">load</span></a> and <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> commands use a decimal number to represent a data and time in seconds. The default value is 0.0, which means the Epoch.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Groonga internally holds the value of Epoch as pair of integer. The first integer represents the value of seconds, on the other hand, the second integer represents the value of micro seconds.
So, Groonga shows the value of Epoch as floating point. Integral part means the value of seconds, fraction part means the value of micro seconds.</p>
</div>
<p>The following example creates a <code class="docutils literal notranslate"><span class="pre">Time</span></code> column and updates existing
records. The first record (<code class="docutils literal notranslate"><span class="pre">"Monkey"</span></code> key record) has the default
value (<code class="docutils literal notranslate"><span class="pre">0.0</span></code>) because it’s not updated.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table ToyBox --name time --type Time
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{"_key":"Flower","time":1234567890.1234569999}
{"_key":"Block","time":-1234567890}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,time
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 3
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "time",
# "Time"
# ]
# ],
# [
# "Monkey",
# 0.0
# ],
# [
# "Flower",
# 1234567890.123457
# ],
# [
# "Block",
# -1234567890.0
# ]
# ]
# ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="longitude-and-latitude-types">
<h2><span class="section-number">4.3.6. </span>Longitude and latitude types<a class="headerlink" href="#longitude-and-latitude-types" title="Permalink to this headline">¶</a></h2>
<p>The longitude and latitude types are divided according to the geographic coordinate system. For more details, see <a class="reference internal" href="../reference/types.html"><span class="doc">Data types</span></a>. To represent a longitude and latitude, Groonga uses a string formatted as follows:</p>
<ul class="simple">
<li><p>“longitude x latitude” in milliseconds (e.g.: “128452975x503157902”)</p></li>
<li><p>“longitude x latitude” in degrees (e.g.: “35.6813819x139.7660839”)</p></li>
</ul>
<p>A number with/without a decimal point represents a longitude or latitude in milliseconds/degrees respectively. Note that a combination of a number with a decimal point and a number without a decimal point (e.g. 35.1x139) must not be used. A comma (‘,’) is also available as a delimiter. The default value is “0x0”.</p>
<p>The following example creates a <code class="docutils literal notranslate"><span class="pre">WGS84GeoPoint</span></code> column and updates
existing records. The second record (<code class="docutils literal notranslate"><span class="pre">"Flower"</span></code> key record) has the
default value (<code class="docutils literal notranslate"><span class="pre">"0x0"</span></code>) because it’s not updated.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table ToyBox --name location --type WGS84GeoPoint
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table ToyBox
[
{"_key":"Monkey","location":"128452975x503157902"}
{"_key":"Block","location":"35.6813819x139.7660839"}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table ToyBox --output_columns _key,location
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 3
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "location",
# "WGS84GeoPoint"
# ]
# ],
# [
# "Monkey",
# "128452975x503157902"
# ],
# [
# "Flower",
# "0x0"
# ],
# [
# "Block",
# "128452975x503157902"
# ]
# ]
# ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="reference-types">
<h2><span class="section-number">4.3.7. </span>Reference types<a class="headerlink" href="#reference-types" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports a reference column, which stores references to records in its associated table. In practice, a reference column stores the IDs of the referred records in the associated table and enables access to those records.</p>
<p>You can specify a column in the associated table to the <code class="docutils literal notranslate"><span class="pre">output_columns</span></code> parameter of a <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> command. The format is <code class="docutils literal notranslate"><span class="pre">Src.Dest</span></code> where Src is the name of the reference column and Dest is the name of the target column. If only the reference column is specified, it is handled as <code class="docutils literal notranslate"><span class="pre">Src._key</span></code>. Note that if a reference does not point to a valid record, a <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> command outputs the default value of the target column.</p>
<p>The following example adds a reference column to the <code class="docutils literal notranslate"><span class="pre">Site</span></code> table
that was created in <a class="reference internal" href="introduction.html#tutorial-introduction-create-table"><span class="std std-ref">Create a table</span></a>. The new
column, named <code class="docutils literal notranslate"><span class="pre">link</span></code>, is designed for storing links among records in
the <code class="docutils literal notranslate"><span class="pre">Site</span></code> table.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table Site --name link --type Site
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Site
[
{"_key":"http://example.org/","link":"http://example.net/"}
]
# [[0, 1337566253.89858, 0.000355720520019531], 1]
select --table Site --output_columns _key,title,link._key,link.title --query title:@this
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 1
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "title",
# "ShortText"
# ],
# [
# "link._key",
# "ShortText"
# ],
# [
# "link.title",
# "ShortText"
# ]
# ],
# [
# "http://example.org/",
# "This is test record 1!",
# "http://example.net/",
# "test record 2."
# ]
# ]
# ]
# ]
</pre></div>
</div>
<p>The <cite>type</cite> parameter of the <a class="reference internal" href="../reference/commands/column_create.html"><span class="doc">column_create</span></a> command specifies the table to be associated with the reference column. In this example, the reference column is associated with the own table. Then, the <a class="reference internal" href="../reference/commands/load.html"><span class="doc">load</span></a> command registers a link from “<a class="reference external" href="http://example.org">http://example.org</a>” to “<a class="reference external" href="http://example.net">http://example.net</a>”. Note that a reference column requires the primary key, not the ID, of the record to be referred to. After that, the link is confirmed by the <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> command. In this case, the primary key and the title of the referred record are output because link._key and link.title are specified to the <cite>output_columns</cite> parameter.</p>
</div>
<div class="section" id="vector-types">
<h2><span class="section-number">4.3.8. </span>Vector types<a class="headerlink" href="#vector-types" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports a vector column, in which each element can store a variable number of values. To create a vector column, specify the COLUMN_VECTOR flag to the <cite>flags</cite> parameter of a <a class="reference internal" href="../reference/commands/column_create.html"><span class="doc">column_create</span></a> command. A vector column is useful to represent a many-to-many relationship.</p>
<p>The previous example used a regular column, so each record could have at most one link. Obviously, the specification is insufficient because a site usually has more than one links. To solve this problem, the following example uses a vector column.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>column_create --table Site --name links --flags COLUMN_VECTOR --type Site
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Site
[
{"_key":"http://example.org/","links":["http://example.net/","http://example.org/","http://example.com/"]},
]
# [[0, 1337566253.89858, 0.000355720520019531], 1]
select --table Site --output_columns _key,title,links._key,links.title --query title:@this
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 1
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "title",
# "ShortText"
# ],
# [
# "links._key",
# "ShortText"
# ],
# [
# "links.title",
# "ShortText"
# ]
# ],
# [
# "http://example.org/",
# "This is test record 1!",
# [
# "http://example.net/",
# "http://example.org/",
# "http://example.com/"
# ],
# [
# "test record 2.",
# "This is test record 1!",
# "test test record three."
# ]
# ]
# ]
# ]
# ]
</pre></div>
</div>
<p>The only difference at the first step is the <cite>flags</cite> parameter that specifies to create a vector column. The <cite>type</cite> parameter of the <a class="reference internal" href="../reference/commands/column_create.html"><span class="doc">column_create</span></a> command is the same as in the previous example. Then, the <a class="reference internal" href="../reference/commands/load.html"><span class="doc">load</span></a> command registers three links from “<a class="reference external" href="http://example.org/">http://example.org/</a>” to “<a class="reference external" href="http://example.net/">http://example.net/</a>”, “<a class="reference external" href="http://example.org/">http://example.org/</a>” and “<a class="reference external" href="http://example.com/">http://example.com/</a>”. After that, the links are confirmed by the <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> command. In this case, the primary keys and the titles are output as arrays because links._key and links.title are specified to the <cite>output_columns</cite> parameter.</p>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">4.3. Various data types</a><ul>
<li><a class="reference internal" href="#overview">4.3.1. Overview</a></li>
<li><a class="reference internal" href="#boolean-type">4.3.2. Boolean type</a></li>
<li><a class="reference internal" href="#numeric-types">4.3.3. Numeric types</a></li>
<li><a class="reference internal" href="#string-types">4.3.4. String types</a></li>
<li><a class="reference internal" href="#date-and-time-type">4.3.5. Date and time type</a></li>
<li><a class="reference internal" href="#longitude-and-latitude-types">4.3.6. Longitude and latitude types</a></li>
<li><a class="reference internal" href="#reference-types">4.3.7. Reference types</a></li>
<li><a class="reference internal" href="#vector-types">4.3.8. Vector types</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="network.html"
title="previous chapter"><span class="section-number">4.2. </span>Remote access</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="search.html"
title="next chapter"><span class="section-number">4.4. </span>Various search conditions</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="search.html" title="4.4. Various search conditions"
>next</a> |</li>
<li class="right" >
<a href="network.html" title="4.2. Remote access"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../tutorial.html" ><span class="section-number">4. </span>Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4.3. </span>Various data types</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2009-2021, Brazil, Inc.
</div>
</body>
</html>
|