Skip to content

Commit d772074

Browse files
authored
Merge pull request #12 from keboola/ujovlado-fix-missing-manifest-support
Fix missing manifest support
2 parents 36b7e40 + eef98e7 commit d772074

File tree

7 files changed

+207
-67
lines changed

7 files changed

+207
-67
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"symfony/filesystem": "^4.0",
1919
"nette/utils": "^2.4",
2020
"keboola/csvmap": "^0.3",
21-
"monolog/monolog": "^1.22"
21+
"monolog/monolog": "^1.22",
22+
"keboola/php-component": "^2.1"
2223
},
2324
"require-dev": {
2425
"phpunit/phpunit": "~5.3",

composer.lock

Lines changed: 165 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Keboola/DynamoDbExtractor/Extractor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Nette\Utils\Strings;
77
use Symfony\Component\Config\Definition\Processor;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use Keboola\Component\Manifest\ManifestManager;
910

1011
class Extractor
1112
{
@@ -61,20 +62,28 @@ public function actionRun(string $outputPath): void
6162
{
6263
$this->validateExports($this->parameters['exports']);
6364

65+
$manifestManager = new ManifestManager($outputPath);
66+
6467
foreach ($this->parameters['exports'] as $exportOptions) {
6568
$export = new Exporter($this->dynamoDbClient, $exportOptions, $outputPath, $this->consoleOutput);
6669

6770
if ($export->hasEnabledExport()) {
6871
$filename = $export->export();
6972
if (file_exists($filename)) {
73+
$webalizedExportName = Strings::webalize($exportOptions['name']);
7074
$parser = new Parser(
71-
Strings::webalize($exportOptions['name']),
75+
$webalizedExportName,
7276
$filename,
7377
$exportOptions['mapping'],
7478
$this->consoleOutput
7579
);
80+
7681
$parser->parseAndWriteCsvFiles();
7782
$export->cleanup();
83+
84+
$manifestManager->writeTableManifestFromArray($outputPath . '/' .$webalizedExportName . '.csv', [
85+
'incremental' => $exportOptions['incremental'],
86+
]);
7887
} else {
7988
$this->consoleOutput->writeln('No documents found for export ' . $exportOptions['name']);
8089
}

tests/Keboola/DynamoDbExtractor/RunExportFromIndex.php renamed to tests/Keboola/DynamoDbExtractor/RunExportFromIndexTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Application;
66
use Symfony\Component\Console\Tester\CommandTester;
77

8-
class RunFullExportTest extends ExtractorTestCase
8+
class RunExportFromIndexTest extends ExtractorTestCase
99
{
1010
/** @var string */
1111
protected $dataDir = '/tmp/run-export-from-index';
@@ -59,9 +59,11 @@ public function testRun()
5959
]);
6060

6161
$expectedFile = $this->dataDir . '/out/tables/10-movies.csv';
62+
$expectedManifestFile = $expectedFile . '.manifest';
6263

6364
$this->assertSame(0, $exitCode);
6465
$this->assertFileExists($expectedFile);
66+
$this->assertFileExists($expectedManifestFile);
6567

6668
$expectedCsv = <<<CSV
6769
"title","year","rating"
@@ -77,5 +79,10 @@ public function testRun()
7779
"X-Men: Days of Future Past","2014",""\n
7880
CSV;
7981
$this->assertEquals($expectedCsv, file_get_contents($expectedFile));
82+
83+
$expectedManifest = <<<JSON
84+
{"destination":"","primary_key":[],"delimiter":",","enclosure":"\"","columns":[],"incremental":true,"metadata":[],"column_metadata":[]}\n
85+
JSON;
86+
$this->assertEquals($expectedManifest, file_get_contents($expectedManifestFile));
8087
}
8188
}

tests/Keboola/DynamoDbExtractor/RunFullExportTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ public function testRun()
5757
]);
5858

5959
$expectedFile = $this->dataDir . '/out/tables/10-movies.csv';
60+
$expectedManifestFile = $expectedFile . '.manifest';
6061

6162
$this->assertSame(0, $exitCode);
6263
$this->assertFileExists($expectedFile);
64+
$this->assertFileExists($expectedManifestFile);
6365

6466
$expectedCsv = <<<CSV
6567
"title","year","rating"
@@ -75,5 +77,10 @@ public function testRun()
7577
"World War Z","2013","7.1"\n
7678
CSV;
7779
$this->assertEquals($expectedCsv, file_get_contents($expectedFile));
80+
81+
$expectedManifest = <<<JSON
82+
{"destination":"","primary_key":[],"delimiter":",","enclosure":"\"","columns":[],"incremental":true,"metadata":[],"column_metadata":[]}\n
83+
JSON;
84+
$this->assertEquals($expectedManifest, file_get_contents($expectedManifestFile));
7885
}
7986
}

tests/Keboola/DynamoDbExtractor/RunWithFilterExpressionTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp()
2929
"name": "10-movies",
3030
"table": "Movies",
3131
"enabled": true,
32-
"incremental": true,
32+
"incremental": false,
3333
"dateFilter": {
3434
"field": "year",
3535
"format": "Y",
@@ -63,15 +63,22 @@ public function testRun()
6363
]);
6464

6565
$expectedFile = $this->dataDir . '/out/tables/10-movies.csv';
66+
$expectedManifestFile = $expectedFile . '.manifest';
6667

6768
$this->assertSame(0, $exitCode);
6869
$this->assertFileExists($expectedFile);
70+
$this->assertFileExists($expectedManifestFile);
6971

7072
$expectedCsv = <<<CSV
7173
"title","year","rating"
7274
"Transformers: Age of Extinction","2014",""
7375
"X-Men: Days of Future Past","2014",""\n
7476
CSV;
7577
$this->assertEquals($expectedCsv, file_get_contents($expectedFile));
78+
79+
$expectedManifest = <<<JSON
80+
{"destination":"","primary_key":[],"delimiter":",","enclosure":"\"","columns":[],"incremental":false,"metadata":[],"column_metadata":[]}\n
81+
JSON;
82+
$this->assertEquals($expectedManifest, file_get_contents($expectedManifestFile));
7683
}
7784
}

0 commit comments

Comments
 (0)