generate-copy.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # generate-copy — generates \copy commands from LDBC BI csv files
  12. set -eu -o pipefail
  13. : "${csvs=bi-sf1-composite-merged-fk/graphs/csv/bi/composite-merged-fk}"
  14. exec 1>copy.sql
  15. printf -- "-- static entitities\n"
  16. for entity in Organisation Place Tag TagClass
  17. do
  18. for csv in "$csvs/initial_snapshot/static/$entity/part-"*.csv
  19. do
  20. printf "\\copy %s FROM '%s' WITH (DELIMITER '|', HEADER, NULL '', FORMAT CSV);\n" "$entity" "$csv"
  21. done
  22. done
  23. printf -- "\n-- dynamic entitites\n"
  24. for entity in Comment Comment_hasTag_Tag Forum Forum_hasMember_Person Forum_hasTag_Tag Person Person_hasInterest_Tag Person_knows_Person Person_studyAt_University Person_workAt_Company Person_likes_Comment Person_likes_Post Post Post_hasTag_Tag
  25. do
  26. for csv in "$csvs/initial_snapshot/dynamic/$entity/part-"*.csv
  27. do
  28. printf "\\copy %s FROM '%s' WITH (DELIMITER '|', HEADER, NULL '', FORMAT CSV);\n" "$entity" "$csv"
  29. # make it symmetric
  30. if [ "$entity" = "Person_knows_Person" ]
  31. then
  32. printf "\\copy %s (creationDate, Person2id, Person1id) FROM '%s' WITH (DELIMITER '|', HEADER, NULL '', FORMAT CSV);\n" "$entity" "$csv"
  33. fi
  34. done
  35. done