-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from PanDAWMS/stage-019-esFormat
Stage 019 transformation Now it can accept data not only from Stage 016, but also from 091 (see #79) -- or any other stage, that produces data in the required format.
- Loading branch information
Showing
18 changed files
with
1,186 additions
and
907 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,91 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
function exception_error_handler($errno, $errstr, $errfile, $errline ) { | ||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); | ||
} | ||
set_error_handler("exception_error_handler"); | ||
|
||
$DEFAULT_INDEX = 'prodsys'; | ||
$ES_INDEX = NULL; | ||
|
||
function check_input($row) { | ||
$required_fields = array('_id', '_type'); | ||
|
||
if (!is_array($row)) { | ||
fwrite(STDERR, "(WARN) Failed to decode message.\n"); | ||
return FALSE; | ||
} | ||
|
||
foreach ($required_fields as $field) { | ||
if (!(isset($row[$field]))) { | ||
fwrite(STDERR, "(WARN) Required field \"$field\" is not set or empty.\n"); | ||
return FALSE; | ||
} | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
function convertIndexToLowerCase(&$a) { | ||
$result = array(); | ||
|
||
foreach (array_keys($a) as $i) { | ||
$result[strtolower($i)] = $a[$i]; | ||
} | ||
|
||
$a = $result; | ||
} | ||
|
||
function constructIndexJson(&$row) { | ||
global $ES_INDEX; | ||
$index = Array( | ||
'index' => Array( | ||
'_index' => $ES_INDEX, | ||
'_type' => $row['_type'], | ||
'_id' => $row['_id'], | ||
) | ||
); | ||
|
||
if (isset($row['_parent'])) { | ||
$index['index']['_parent'] = $row['_parent']; | ||
} | ||
|
||
foreach ($index as $key => $val) { | ||
unset($row[$key]); | ||
} | ||
|
||
return $index; | ||
} | ||
|
||
if (isset($argv[1])) { | ||
$h = fopen($argv[1], "r"); | ||
} else { | ||
$h = fopen('php://stdin', 'r'); | ||
} | ||
|
||
$ES_INDEX = getenv('ES_INDEX'); | ||
if (!$ES_INDEX) { | ||
$ES_INDEX = $DEFAULT_INDEX; | ||
} | ||
|
||
if ($h) { | ||
while (($line = fgets($h)) !== false) { | ||
$row = json_decode($line,true); | ||
|
||
if (!check_input($row)) { | ||
fwrite(STDERR, "(WARN) Skipping message (\"".substr($row, 45)."\").\n"); | ||
continue; | ||
} | ||
|
||
convertIndexToLowerCase($row); | ||
|
||
$index = constructIndexJson($row); | ||
|
||
echo json_encode($index)."\n"; | ||
echo json_encode($row)."\n"; | ||
} | ||
} | ||
|
||
fclose($h); | ||
|
||
?> |
This file contains 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 @@ | ||
../../016_task2es/output/sample.ndjson |
This file contains 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 @@ | ||
../../091_datasetsRucio/output/datasets.ndjson |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,15 @@ | ||
#/usr//bin/env bash | ||
|
||
base_dir=$(cd "$(dirname "$(readlink -f "$0")")"; pwd) | ||
|
||
ES_CONFIG=$base_dir/../../Elasticsearch/config/es | ||
|
||
[ -r "$ES_CONFIG" ] \ | ||
|| { echo "Can't access configuration file: $ES_CONFIG" >&2 \ | ||
&& exit 1; } | ||
|
||
set -a | ||
. "$ES_CONFIG" | ||
set +a | ||
|
||
$base_dir/esFormat.php |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.