Project

General

Profile

task #6020 » split-kdata.awk

Andreas Kohlbecker, 09/20/2016 06:35 PM

 
1
BEGIN {
2
    FS="\t"
3
    tag_index = 1
4
}
5
NR>1{
6
    print NR"# "$0
7
    n = split($5, t, ",")
8
    #print "n: "n
9
    for (i = 1; i <= n; i++) {
10
        tag = t[i]
11
        #print "tag["i"]: "tag
12
        gsub(/^[ \t]+|[ \t]+$/, "", tag)
13
        id = get_index(taglist, tag, tagcount)
14
        if( id < 0){
15
            # unkown tag, add it to the list
16
            taglist[tag_index] = tag
17
            tagcount[tag_index] = 1
18
            id = tag_index
19
            tag_index++
20
        }
21
        if( tag == "" ) {
22
                continue
23
        }
24
        print "INSERT INTO taggings (tag_id, taggable_id, taggable_type, context, created_at) VALUES("id", "$3", 'Issue', 'tags', NOW());" > "taggings.sql"
25
    }
26
    
27
}
28
END {
29
    for ( k in taglist){
30
        print "INSERT INTO tags (id, name, taggings_count) VALUES("k", '"taglist[k]"', "tagcount[k]");" > "tags.sql"
31
        
32
    }
33
}
34

    
35
function get_index(array, value, count_array){
36
    for ( k in array) {
37
        if(array[k] == value){
38
           count_array[k] = count_array[k] + 1
39
           return k
40
        } 
41
    }
42
    
43
    return -1
44
}
45

    
46
# The following  SQL statement could be used to update the issue journal, but this is not necessary:
47
# ----
48
# insert into journal_details (journal_id, property, prop_key, old_value, value) (
49
#    select jd.journal_id, 'attr', 'tag_list', null, 'swagger, memory'  from journals j join journal_details jd on j.id=jd.journal_id
50
#        where j.journalized_id = 4414 order by j.created_on DESC LIMIT 1
51
#    )
52
# ----
(1-1/2)