Guest User

Untitled

a guest
Nov 15th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -a
  4. source variables-2.file
  5. set +a
  6.  
  7. function maptypes(){
  8. case "$1" in
  9. "STRING")
  10. Value=keyword
  11. ;;
  12. "INT")
  13. Value=long
  14. ;;
  15. "BIGINT")
  16. Value=long
  17. ;;
  18. "TINYINT")
  19. Value=integer
  20. ;;
  21. "SMALLINT")
  22. Value=integer
  23. ;;
  24. "CHAR")
  25. Value=keyword
  26. ;;
  27. "VARCHAR")
  28. Value=keyword
  29. ;;
  30. "FLOAT")
  31. Value=double
  32. ;;
  33. "DOUBLE")
  34. Value=double
  35. ;;
  36. "TIMESTAMP")
  37. Value=date
  38. ;;
  39. "NUMBER")
  40. Value=double
  41. ;;
  42. "DATETIME")
  43. Value=date
  44. ;;
  45. esac
  46. }
  47.  
  48. TABLES=$(echo $TABLES_ALLOWED | tr "," "\n")
  49.  
  50. echo TABLES ARE $TABLES
  51.  
  52. append="1"
  53. for each in ${TABLES}; do
  54. table=$(echo $each | cut -d. -f2)
  55. echo Creating index $each$append in ES
  56. curl -X PUT "10.34.234.112:9200/$each$append" -H 'Content-Type: application/json' -d'{ }'
  57. echo -e "\n---------------------------------------------------------------------------------------------------------------------------\n"
  58. ${MASTER_INSTALL_DIR}/${SERVICE_NAME}/tungsten/tungsten-replicator/bin/ddlscan -template ddl-mysql-vertica-staging.vm -user ${MYSQL_EXTRACTOR_USER} -pass ${MYSQL_EXTRACTOR_PASS} -url jdbc:mysql:thin://${MYSQL_SOURCE_IP}:3306/ -db ${MYSQLDUMP_DB} -tables ${table} > /tmp/out
  59.  
  60. cat /tmp/out
  61. sed -e 's/\/\*.*\*\///g' /tmp/out > /tmp/var
  62. cat /tmp/var
  63. mappings1=$(sed -n -e '/tungsten_opcode/,/ORDER_BY/p' /tmp/var | sed 's/,//g' | sed 's/(.*)//g')
  64. echo Mappings is $mappings1
  65. arr=($mappings1)
  66. echo -e "\n-------------------------------------------------------------------------------------------------------------------------------\n"
  67. for i in "${arr[@]}"
  68. do
  69. echo "$i"
  70. done
  71. echo Creating mappings for table $each$append
  72. for ((i = 0; i < ${#arr[@]}; ++i)); do
  73. if [[ ${arr[$i]} == "ORDER" ]]; then
  74. echo Found ${arr[$i]}.Breaking from loop.
  75. break
  76. fi
  77. rem=$(( $i % 2 ))
  78. if [ $rem -eq 0 ]
  79. then
  80. ColName=$(echo ${arr[$i]} | sed 's/\"//g')
  81. if [[ $ColName == "tungsten_commit_timestamp" ]]
  82. then
  83. echo Changing $ColName to source_commit_timestamp
  84. ColName="source_commit_timestamp"
  85. fi
  86. echo ColName= $ColName
  87. else
  88. Value=${arr[$i]}
  89. echo Value= $Value
  90. maptypes ${arr[$i]}
  91. echo Mapping $ColName to $Value
  92. curl -X PUT "10.34.234.112:9200/$each$append/_mapping/$each" -H 'Content-Type: application/json' -d'
  93. {
  94. "properties": {
  95. "'$ColName'": {
  96. "type": "'$Value'"
  97. }
  98. }
  99. }'
  100. fi
  101. done
  102. done
Add Comment
Please, Sign In to add comment