Skip to content

Commit

Permalink
Merge pull request #19 from keboola/adamvyborny-CM-573-fix-writing-bo…
Browse files Browse the repository at this point in the history
…ol-values

Fix writing bool values
AdamVyborny authored Apr 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 82a2f70 + f9e210c commit 0765cd2
Showing 15 changed files with 100,122 additions and 60 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
"ext-intl": "*",
"ext-json": "*",
"ext-mongodb": "*",
"keboola/csv": "^3.0",
"keboola/csvmap": "^2.1",
"keboola/csv": "^4.0",
"keboola/csvmap": "^2.2",
"keboola/php-component": "^9.0",
"keboola/retry": "^0.5.0",
"keboola/ssh-tunnel": "^2.0",
100 changes: 50 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Config/ExportOptions.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class ExportOptions
private bool $enabled;
private bool $incrementalFetching;
private string $name;
/** @var array<mixed, mixed> */
/** @var array<string, mixed> */
private array $mapping;
private string $mode;
private ?int $limit;
@@ -76,7 +76,7 @@ public function getName(): string
}

/**
* @return array<int|string, mixed>
* @return array<string, mixed>
*/
public function getMapping(): array
{
2 changes: 1 addition & 1 deletion src/Parse.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
class Parse
{
private string $name;
/** @var array<int|string, mixed> */
/** @var array<string, mixed> */
private array $mapping;
private ConsoleOutput $consoleOutput;

10 changes: 5 additions & 5 deletions src/Parser/Mapping.php
Original file line number Diff line number Diff line change
@@ -19,17 +19,17 @@

class Mapping implements ParserInterface
{
/** @var array<int|string, mixed> */
/** @var array<string, mixed> */
private array $mapping;
private bool $includeParentInPK;
private string $path;
private string $name;
private Filesystem $filesystem;
/** @var array<string, array{path: string, primaryKey: array<int, string>|string}> */
/** @var array<string, array{path: string, primaryKey: array<string>|string|null}>. */
private array $manifestData = [];

/**
* @param array<int|string, mixed> $mapping
* @param array<string, mixed> $mapping
*/
public function __construct(
string $name,
@@ -58,7 +58,7 @@ public function parse(array $data): void
$mapper->parse($data, $userData);
} catch (BadConfigException|BadDataException $e) {
throw new UserException(sprintf('Invalid mapping configuration: %s', $e->getMessage()));
} catch (TypeError $e) {
} catch (TypeError) { // @phpstan-ignore-line
throw new UserException('CSV writing error. Header and mapped documents must be scalar values.');
}

@@ -105,7 +105,7 @@ protected function prependHeader(Table $file, string &$content): void
}

/**
* @return array<string, array{path: string, primaryKey: array<int, string>|string}>
* @return array<string, array{path: string, primaryKey: array<string>|string|null}>
*/
public function getManifestData(): array
{
20 changes: 20 additions & 0 deletions tests/datasets/bool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"_id": {
"$oid": "5716054bee6e764c94fa7ddd"
},
"bool": true
},
{
"_id": {
"$oid": "5716054bee6e764c94fa8181"
},
"bool": false
},
{
"_id": {
"$oid": "5716054bee6e764c94fa8213"
},
"bool": null
}
]
1 change: 1 addition & 0 deletions tests/functional/export-bool-values/expected-code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
3 changes: 3 additions & 0 deletions tests/functional/export-bool-values/expected-stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Connected to mongodb://mongodb:27017/test
Exporting "export-all"
Done "export-all", parsed 3 records in total
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"id","bool"
"5716054bee6e764c94fa7ddd","1"
"5716054bee6e764c94fa8181","0"
"5716054bee6e764c94fa8213",""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"primary_key":null,"incremental":false}
10 changes: 10 additions & 0 deletions tests/functional/export-bool-values/setUp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types = 1);

use MongoExtractor\FunctionalTests\DatadirTest;
use MongoExtractor\Tests\Traits\ImportDatasetTrait;

return static function (DatadirTest $test): void {
(new class { use ImportDatasetTrait; })::importDatatasetNoAuthDb('restaurants', 'bool.json');
};
22 changes: 22 additions & 0 deletions tests/functional/export-bool-values/source/data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"parameters": {
"db": {
"host": "mongodb",
"port": 27017,
"database": "test"
},
"collection": "restaurants",
"tableName": "export-all",
"mapping": {
"_id.$oid": {
"type": "column",
"mapping": {
"destination": "id"
}
},
"bool": "bool"
},
"mode": "mapping",
"sort": "{_id: 1}"
}
}
100,001 changes: 100,001 additions & 0 deletions tests/functional/run-action-big-data/expected/data/out/tables/big-data.csv

Large diffs are not rendered by default.

0 comments on commit 0765cd2

Please sign in to comment.