Skip to content

Commit c5ee84f

Browse files
authored
Add getschema (#257)
1 parent b114818 commit c5ee84f

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: getschema
3+
description: 'This page explains how to use the getschema operator in APL.'
4+
---
5+
6+
The `getschema` operator in APL returns the schema of a dataset, including field names and their data types. You can use it to inspect the structure of a dataset before performing queries or transformations. This operator is useful when exploring new datasets, verifying data consistency, or debugging queries.
7+
8+
## For users of other query languages
9+
10+
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
11+
12+
<AccordionGroup>
13+
<Accordion title="Splunk SPL users">
14+
15+
In Splunk SPL, you can use the `fieldsummary` command to get schema-related information about a dataset. However, `getschema` in APL is more direct and focused specifically on returning field names and types without additional summary statistics.
16+
17+
<CodeGroup>
18+
```sql Splunk example
19+
| fieldsummary
20+
```
21+
22+
```kusto APL equivalent
23+
['sample-http-logs']
24+
| getschema
25+
```
26+
</CodeGroup>
27+
28+
</Accordion>
29+
<Accordion title="ANSI SQL users">
30+
31+
In ANSI SQL, retrieving schema information is typically done using `INFORMATION_SCHEMA` queries. APL’s `getschema` operator provides a more straightforward way to get schema details without requiring system views.
32+
33+
<CodeGroup>
34+
```sql SQL example
35+
SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sample_http_logs';
36+
```
37+
38+
```kusto APL equivalent
39+
['sample-http-logs']
40+
| getschema
41+
```
42+
</CodeGroup>
43+
44+
</Accordion>
45+
</AccordionGroup>
46+
47+
## Usage
48+
49+
### Syntax
50+
51+
```kusto
52+
| getschema
53+
```
54+
55+
### Parameters
56+
57+
The `getschema` operator does not take any parameters.
58+
59+
### Returns
60+
61+
| Field | Type | Description |
62+
|-------------|--------|--------------------------------------|
63+
| ColumnName | string | The name of the field in the dataset. |
64+
| ColumnOrdinal | number | The index number of the field in the dataset.
65+
| ColumnType | string | The data type of the field. |
66+
| DataType | string | The APL-internal name for the data type of the field. |
67+
68+
## Use case example
69+
70+
You can use `getschema` to explore the schema of your log data before running queries.
71+
72+
**Query**
73+
74+
```kusto
75+
['sample-http-logs'] | getschema
76+
```
77+
78+
[Run in Playground](https://play.axiom.co/axiom-play-qf1k/query?initForm=%7B%22apl%22%3A%22%5B'sample-http-logs'%5D%20%7C%20getschema%22%7D)
79+
80+
**Output**
81+
82+
| ColumnName | DataType | ColumnOrdinal | ColumnType |
83+
|---------------------|-----------------|---------------|-----------------|
84+
| _sysTime | datetime | 0 | datetime |
85+
| _time | datetime | 1 | datetime |
86+
| content_type | string | 2 | string |
87+
| geo.city | string | 3 | string |
88+
| geo.country | string | 4 | string |
89+
| id | string | 5 | string |
90+
91+
This query helps you verify the available fields and their data types before further analysis.
92+
93+
## List of related operators
94+
95+
- [project](/apl/tabular-operators/project-operator): Use `project` to select specific fields instead of retrieving the entire schema.
96+
- [extend](/apl/tabular-operators/extend-operator): Use `extend` to add new computed fields to your dataset after understanding the schema.
97+
- [summarize](/apl/tabular-operators/summarize-operator): Use `summarize` for aggregations once you verify field types using `getschema`.
98+
- [where](/apl/tabular-operators/where-operator): Use `where` to filter datasets based on field values after checking their schema.
99+
- [order](/apl/tabular-operators/order-operator): Use `order by` to sort datasets after verifying schema details.

apl/tabular-operators/overview.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The table summarizes the tabular operators available in APL.
1515
| [extend](/apl/tabular-operators/extend-operator) | Returns the original dataset with one or more new fields appended, based on the defined expressions. |
1616
| [extend-valid](/apl/tabular-operators/extend-valid-operator) | Returns a table where the specified fields are extended with new values based on the given expression for valid rows. |
1717
| [externaldata](/apl/tabular-operators/externaldata-operator) | Returns a table with the specified schema, containing data retrieved from an external source. |
18+
| [getschema](/apl/tabular-operators/getschema-operator) | Returns the schema of a dataset, including field names and their data types |
1819
| [join](/apl/tabular-operators/join-operator) | Returns a dataset containing rows from two different tables based on conditions. |
1920
| [limit](/apl/tabular-operators/limit-operator) | Returns the top N rows from the input dataset. |
2021
| [lookup](/apl/tabular-operators/lookup-operator) | Returns a dataset where rows from one dataset are enriched with matching columns from a lookup table based on conditions. |

docs.json

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@
406406
"apl/tabular-operators/extend-operator",
407407
"apl/tabular-operators/extend-valid-operator",
408408
"apl/tabular-operators/externaldata-operator",
409+
"apl/tabular-operators/getschema-operator",
409410
"apl/tabular-operators/join-operator",
410411
"apl/tabular-operators/limit-operator",
411412
"apl/tabular-operators/lookup-operator",

0 commit comments

Comments
 (0)