> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querymap.md).

# QueryMap

This BIF will iterate over each row in the query and invoke the callback function for each item so you can do any operation on the row and return a new value that will be set at the same index in a new query.

The callback function will be passed the row as a struct, the current row number (1-based), and the query itself.

* If the callback requires strict arguments, it will only receive the row as a struct.
* If the callback does not require strict arguments, it will receive the row as a struct, the row number (1-based), and the query itself.

## Parallel Execution

If the `parallel` argument is set to true, and no `max_threads` are sent, the map will be executed in parallel using a ForkJoinPool with parallel streams. If `max_threads` is specified, it will create a new ForkJoinPool with the specified number of threads to run the map in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to map, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

## Method Signature

```
QueryMap(query=[query], callback=[function:Function], parallel=[boolean], maxThreads=[any], virtual=[boolean])
```

### Arguments

| Argument     | Type                | Required | Description                                                                                                                                                                                                                                                                             | Default |
| ------------ | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `query`      | `query`             | `true`   | The query to iterate over                                                                                                                                                                                                                                                               |         |
| `callback`   | `function:Function` | `true`   | The function to invoke for each item. The function will be passed 3 arguments: the row, the currentRow, the query. You can alternatively pass a Java Function which will only receive the 1st arg.                                                                                      |         |
| `parallel`   | `boolean`           | `false`  | Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.                                                                                                                                                             | `false` |
| `maxThreads` | `any`               | `false`  | <p>The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool.<br>If parallel is false, this argument is ignored. If a boolean is passed it will be used as the virtual thread argument</p> |         |
| `virtual`    | `boolean`           | `false`  | Whether to use virtual threads when running the filter in parallel. Defaults to false. Ignored if parallel is false.                                                                                                                                                                    | `false` |

## Examples

### Maps query results

Manipulates query column

[Run Example](https://try.boxlang.io/?code=eJxlj0FLxDAQhc%2FJr3jkIF0Iwnq09NY9LNgVoeBBPMTd6RrdpmuaGIrsf3dSZUU9Zebjvbw3jtKICm%2BR%2FLShVEDZnQ42HEhpnl2gPXn9bvz22XhGD5DiQwrBMoVrLHWev%2FS8qpoSTdhRRyaMaH3sjVNSnPQv19UfV2Mckjm8jhgcmmGYLfIRi1ImbwPVsT8WcLkqI9lFtw2Wpb053uXiBYybcPv0ggU4xnZFXi7XNaoKS4Z5a9ftzYpPVZvVPWfi4oeWUngK0buMSnmSHDV%2FzPL5bcx3vj5n%2Fi93xp8Zw2OR)

```java
news = queryNew( "id,title", "integer,varchar", [ 
	{
		"id" : 1,
		"title" : "Dewey defeats Truman"
	},
	{
		"id" : 2,
		"title" : "Man walks on Moon"
	}
] );
writeDump( news );

function mapQuery( any Obj ) {
	if( Obj.ID == 1 ) Obj.TITLE = "NEW: " & Obj.TITLE;
	return Obj;
}
newQuery = QueryMap( news, mapQuery );
writeDump( newQuery );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJx1UE1Lw0AQPWd%2FxWNPCQ6SCNaGUEENHgQrIp5CD2kz1YD5cJIYgvjfnZUKIukyC7Mz7828fS037RtjhceBZVrz6MPWecVUNFvKX9gS7Ecuu9dcqMh7prLutZbBeJnxPPs0dKUlzW6EtZ3q9RHFFyEh0kDgeqHxNnQgPEs3g4%2FPj%2BFvhYsZwuLogruymsEvl%2F%2FxZoMgMcKdfv7dff4%2Bb320P34QfFzVE6QZ6TdZD9WW5fDkXSNFxz0CrC7xaTwFZLDOMGx0oFublvu9ujnpUccUcJo%2BXBP%2B6joLowVBI9ZBAU4QJTqK%2B0FqR0jMl9M4SqmEoVJ5Tq5WvgF9r3EJ)

```java
people = QueryNew( "name,dob,age", "varchar,date,int", [ 
	[
		"Susi",
		CreateDate( 1970, 1, 1 ),
		0
	],
	[
		"Urs",
		CreateDate( 1995, 1, 1 ),
		0
	],
	[
		"Fred",
		CreateDate( 1960, 1, 1 ),
		0
	],
	[
		"Jim",
		CreateDate( 1988, 1, 1 ),
		0
	]
] );
res = queryMap( people, ( Any row, Any rowNumber, Any recordset ) => {
	row[ "age" ] = DateDiff( "yyyy", row.DOB, CreateDate( 2016, 6, 9 ) ) + 1;
	return row;
} );
writeDump( res );

```

## Related

* [QueryAddColumn](/boxlang-language/reference/built-in-functions/query/queryaddcolumn.md)
* [QueryAddRow](/boxlang-language/reference/built-in-functions/query/queryaddrow.md)
* [QueryAppend](/boxlang-language/reference/built-in-functions/query/queryappend.md)
* [QueryClear](/boxlang-language/reference/built-in-functions/query/queryclear.md)
* [QueryColumnArray](/boxlang-language/reference/built-in-functions/query/querycolumnarray.md)
* [QueryColumnCount](/boxlang-language/reference/built-in-functions/query/querycolumncount.md)
* [QueryColumnData](/boxlang-language/reference/built-in-functions/query/querycolumndata.md)
* [QueryColumnExists](/boxlang-language/reference/built-in-functions/query/querycolumnexists.md)
* [QueryColumnList](/boxlang-language/reference/built-in-functions/query/querycolumnlist.md)
* [QueryCurrentRow](/boxlang-language/reference/built-in-functions/query/querycurrentrow.md)
* [QueryDeleteColumn](/boxlang-language/reference/built-in-functions/query/querydeletecolumn.md)
* [QueryDeleteRow](/boxlang-language/reference/built-in-functions/query/querydeleterow.md)
* [QueryEach](/boxlang-language/reference/built-in-functions/query/queryeach.md)
* [QueryEvery](/boxlang-language/reference/built-in-functions/query/queryevery.md)
* [QueryFilter](/boxlang-language/reference/built-in-functions/query/queryfilter.md)
* [QueryGetCell](/boxlang-language/reference/built-in-functions/query/querygetcell.md)
* [QueryGetResult](/boxlang-language/reference/built-in-functions/query/querygetresult.md)
* [QueryInsertAt](/boxlang-language/reference/built-in-functions/query/queryinsertat.md)
* [QueryKeyExists](/boxlang-language/reference/built-in-functions/query/querykeyexists.md)
* [QueryNew](/boxlang-language/reference/built-in-functions/query/querynew.md)
* [QueryNone](/boxlang-language/reference/built-in-functions/query/querynone.md)
* [QueryPrepend](/boxlang-language/reference/built-in-functions/query/queryprepend.md)
* [QueryRecordCount](/boxlang-language/reference/built-in-functions/query/queryrecordcount.md)
* [QueryRecordCount](/boxlang-language/reference/built-in-functions/query/queryrecordcount.md)
* [QueryReduce](/boxlang-language/reference/built-in-functions/query/queryreduce.md)
* [QueryRegisterFunction](/boxlang-language/reference/built-in-functions/query/queryregisterfunction.md)
* [QueryReverse](/boxlang-language/reference/built-in-functions/query/queryreverse.md)
* [QueryRowData](/boxlang-language/reference/built-in-functions/query/queryrowdata.md)
* [QueryRowSwap](/boxlang-language/reference/built-in-functions/query/queryrowswap.md)
* [QuerySetCell](/boxlang-language/reference/built-in-functions/query/querysetcell.md)
* [QuerySetRow](/boxlang-language/reference/built-in-functions/query/querysetrow.md)
* [QuerySlice](/boxlang-language/reference/built-in-functions/query/queryslice.md)
* [QuerySome](/boxlang-language/reference/built-in-functions/query/querysome.md)
* [QuerySort](/boxlang-language/reference/built-in-functions/query/querysort.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querymap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
