|
| 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. |
0 commit comments