Skip to content

Commit

Permalink
Fixed an issue causing error when defining column options
Browse files Browse the repository at this point in the history
  • Loading branch information
nick committed Jan 7, 2025
1 parent e3e0841 commit 096676a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Manticoresearch/Endpoints/Indices/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ class Create extends EmulateBySql
*/
protected $index;

protected function buildOptionsExpr($options) {
$exprParts = [];
foreach ($options as $k => $v) {
$exprParts[] = is_string($k) ? "$k='$v'" : $v;
}

return ' ' . implode(' ', $exprParts);
}

public function setBody($params = null) {
if (isset($this->index)) {
$columns = [];
if (isset($params['columns'])) {
foreach ($params['columns'] as $name => $settings) {
$column = '`' . $name . '` ' . $settings['type'];
if (isset($settings['options']) && sizeof($settings['options']) > 0) {
$column .= ' ' . implode(' ', $settings['options']);
$column .= $this->buildOptionsExpr($settings['options']);
}
$columns[] = $column;
}
Expand All @@ -47,6 +56,7 @@ public function setBody($params = null) {
}
}
}

return parent::setBody(
['query' => 'CREATE TABLE '.
(isset($params['silent']) && $params['silent'] === true ? ' IF NOT EXISTS ' : '').
Expand Down
2 changes: 1 addition & 1 deletion test/Manticoresearch/Endpoints/Indices/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testCreateTableWithOptions() {
'columns' => [
'title' => [
'type' => 'text',
'options' => ['indexed', 'stored'],
'options' => ['indexed', 'stored', 'engine' => 'columnar'],
],
'price' => [
'type' => 'float',
Expand Down

0 comments on commit 096676a

Please sign in to comment.