-
Notifications
You must be signed in to change notification settings - Fork 91
docs: DOC-1420: Groovy getColumnSource reference doc
#8153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
elijahpetty
wants to merge
1
commit into
deephaven:main
Choose a base branch
from
elijahpetty:doc-1420
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
docs/groovy/reference/table-operations/metadata/getColumnSource.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| title: getColumnSource | ||
| --- | ||
|
|
||
| The `getColumnSource` method returns a `ColumnSource` that provides access to a column's data by **row key**, not positional index. Several overloads can cast the result to a target type so you don't need an explicit cast when the column's data type is known. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```groovy syntax | ||
| table.getColumnSource(sourceName) | ||
| table.getColumnSource(sourceName, clazz) | ||
| table.getColumnSource(sourceName, clazz, componentType) | ||
| table.getColumnSource(columnDefinition) | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| <ParamTable> | ||
| <Param name="sourceName" type="String"> | ||
|
|
||
| The name of the column. | ||
|
|
||
| </Param> | ||
| <Param name="clazz" type="Class<? extends T>"> | ||
|
|
||
| The target data type to cast the `ColumnSource` to. | ||
|
|
||
| </Param> | ||
| <Param name="componentType" type="Class<?>"> | ||
|
|
||
| The target component type, which is useful for array or vector columns. May be `null`. | ||
|
|
||
| </Param> | ||
| <Param name="columnDefinition" type="ColumnDefinition<? extends T>"> | ||
|
|
||
| A `ColumnDefinition` whose data type and component type are used to cast the `ColumnSource`. The column name is taken from `columnDefinition.getName()`. | ||
|
|
||
| </Param> | ||
| </ParamTable> | ||
|
|
||
| ## Returns | ||
|
|
||
| A `ColumnSource` for the requested column, parameterized by the target type when `clazz`, `componentType`, or a `columnDefinition` is provided. | ||
|
|
||
| > [!IMPORTANT] | ||
| > `ColumnSource` methods like `get(rowKey)` use **row keys**, not positional indices. Row keys are the internal identifiers for rows and may not match positional indices, especially in filtered or modified tables. | ||
|
|
||
| ## Examples | ||
|
|
||
| The following example retrieves a `ColumnSource` by name and reads a value by row key: | ||
|
|
||
| ```groovy order=:log | ||
| source = newTable( | ||
| intCol("Integers", 1, 2, 3, 4, 5) | ||
| ) | ||
|
|
||
| columnSource = source.getColumnSource("Integers") | ||
| println columnSource.getInt(2) | ||
| ``` | ||
|
|
||
| The following example casts the `ColumnSource` to a target type using a `Class` and using a `ColumnDefinition` from the table's definition: | ||
|
|
||
| ```groovy order=:log | ||
| source = newTable( | ||
| intCol("Integers", 1, 2, 3, 4, 5) | ||
| ) | ||
|
|
||
| // Cast to a target type by class | ||
| intSource = source.getColumnSource("Integers", int.class) | ||
| println intSource.getInt(2) | ||
|
|
||
| // Cast using a ColumnDefinition from the table's definition | ||
| intDef = source.getDefinition().getColumn("Integers") | ||
| defSource = source.getColumnSource(intDef) | ||
| println defSource.getInt(2) | ||
| ``` | ||
|
|
||
| ## Related documentation | ||
|
|
||
| - [Extract table values](../../../how-to-guides/extract-table-value.md) | ||
| - [getDefinition](./getDefinition.md) | ||
| - [`ColumnSource`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/ColumnSource.html) | ||
| - [`ColumnDefinition`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/ColumnDefinition.html) | ||
| - [Javadoc](https://deephaven.io/core/javadoc/io/deephaven/engine/table/Table.html#getColumnSource(java.lang.String)) | ||
| - [Javadoc (ColumnDefinition overload)](https://deephaven.io/core/javadoc/io/deephaven/engine/table/Table.html#getColumnSource(io.deephaven.engine.table.ColumnDefinition)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file":"reference/table-operations/metadata/getColumnSource.md","objects":{"source":{"type":"Table","data":{"columns":[{"name":"Integers","type":"int"}],"rows":[[{"value":"1"}],[{"value":"2"}],[{"value":"3"}],[{"value":"4"}],[{"value":"5"}]]}},":log":{"type":"Log","data":"3\n"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file":"reference/table-operations/metadata/getColumnSource.md","objects":{"source":{"type":"Table","data":{"columns":[{"name":"Integers","type":"int"}],"rows":[[{"value":"1"}],[{"value":"2"}],[{"value":"3"}],[{"value":"4"}],[{"value":"5"}]]}},":log":{"type":"Log","data":"3\n3\n"}}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is dangerous. You can't just make up a row key. You need to dereference it through a rowset.
We also should not encourage using getInt or any other single-value accessors.