Grouping similar elements xquery - xquery

Thanks for the quick response. I tried both the answers. It is not working as I expected. Please find the below Input and the expected Output. Thanks in Advance
Input:
<Billing>
<billSummary>
<billTo>
<accountNumber>130212192</accountNumber>
<MSISDN>1234567890</MSISDN>
</billTo>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>ONE_TIME</typeCode>
<amount>100.12</amount>
<description>ONE_TIME_CHARGE</description>
</charge>
<charge>
<typeCode>ACCESS</typeCode>
<amount>100.12</amount>
<description>ACCESS_CHARGE</description>
</charge>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>FEATURE</typeCode>
<amount>100.12</amount>
<description>FEATURE_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
<charge>
<typeCode>AIRTIME</typeCode>
<amount>100.12</amount>
<description>AIRTIME_CHARGE</description>
</charge>
<charge>
<typeCode>LONG_DISTANCE</typeCode>
<amount>100.12</amount>
<description>LONG_DISTANCE_CHARGE</description>
</charge>
<charge>
<typeCode>ROAMING</typeCode>
<amount>100.12</amount>
<description>ROAMING_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
</billSummary>
<billSummary>
<billTo>
<accountNumber>130212192</accountNumber>
<MSISDN>1234567890</MSISDN>
</billTo>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>ONE_TIME</typeCode>
<amount>100.12</amount>
<description>ONE_TIME_CHARGE</description>
</charge>
<charge>
<typeCode>ACCESS</typeCode>
<amount>100.12</amount>
<description>ACCESS_CHARGE</description>
</charge>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>FEATURE</typeCode>
<amount>100.12</amount>
<description>FEATURE_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
<charge>
<typeCode>AIRTIME</typeCode>
<amount>100.12</amount>
<description>AIRTIME_CHARGE</description>
</charge>
<charge>
<typeCode>LONG_DISTANCE</typeCode>
<amount>100.12</amount>
<description>LONG_DISTANCE_CHARGE</description>
</charge>
<charge>
<typeCode>ROAMING</typeCode>
<amount>100.12</amount>
<description>ROAMING_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
</billSummary>
</Billing>
Expected Output:
<Billing>
<billSummary>
<billTo>
<accountNumber>130212192</accountNumber>
<MSISDN>1234567890</MSISDN>
</billTo>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>ONE_TIME</typeCode>
<amount>100.12</amount>
<description>ONE_TIME_CHARGE</description>
</charge>
<charge>
<typeCode>ACCESS</typeCode>
<amount>100.12</amount>
<description>ACCESS_CHARGE</description>
</charge>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>FEATURE</typeCode>
<amount>100.12</amount>
<description>FEATURE_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
<charge>
<typeCode>AIRTIME</typeCode>
<amount>100.12</amount>
<description>AIRTIME_CHARGE</description>
</charge>
<charge>
<typeCode>LONG_DISTANCE</typeCode>
<amount>100.12</amount>
<description>LONG_DISTANCE_CHARGE</description>
</charge>
<charge>
<typeCode>ROAMING</typeCode>
<amount>100.12</amount>
<description>ROAMING_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
</billSummary>
<billSummary>
<billTo>
<accountNumber>130212192</accountNumber>
<MSISDN>1234567890</MSISDN>
</billTo>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>ONE_TIME</typeCode>
<amount>100.12</amount>
<description>ONE_TIME_CHARGE</description>
</charge>
<charge>
<typeCode>ACCESS</typeCode>
<amount>100.12</amount>
<description>ACCESS_CHARGE</description>
</charge>
<tax>
<amount>100.12</amount>
<description>TAXES</description>
</tax>
<charge>
<typeCode>FEATURE</typeCode>
<amount>100.12</amount>
<description>FEATURE_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
<charge>
<typeCode>AIRTIME</typeCode>
<amount>100.12</amount>
<description>AIRTIME_CHARGE</description>
</charge>
<charge>
<typeCode>LONG_DISTANCE</typeCode>
<amount>100.12</amount>
<description>LONG_DISTANCE_CHARGE</description>
</charge>
<charge>
<typeCode>ROAMING</typeCode>
<amount>100.12</amount>
<description>ROAMING_CHARGE</description>
</charge>
<deduction>
<amount>100.12</amount>
<description>ADJUSTMENTS</description>
</deduction>
</billSummary>
</Billing>

How about this:
doc("c:\temp\temp.xml")/
<billSummary>
{
for $e in billSummary/*
order by local-name($e)
return $e
}
</billSummary>

Order by node names:
<billSummary>
{
for $i in /billSummary/*
order by $i/name()
return $i
}
</billSummary>
In case you want to group only items inside each bill, loop over all <billSummary/>-nodes:
for $bill in //billSummary
return
<billSummary>
{
for $item in $bill/*
order by $item/name()
return $item
}
</billSummary>
If you need to wrap some node around your answer, you should be able to do it yourself; your question does not contain the information necessary.

Related

How to count the duplicate lines in a file and find the most duplicated line?

Or even better, to show me how many times was certain element copied in the map. The map was created like this:
fun prirazovac() {
var lineNumber = 0
File("src/60.ips.txt").forEachLine {
lineNumber++
val ipcode = mutableMapOf(lineNumber to it)
for (ii in 1..200) {
for (i in 200 downTo 1) {
val truth = (ipcode.get(ii)== ipcode.get(i))
if (truth) {
println(ipcode)
}
}
}
}
}
60.ips.txt:
66.249.64.33
66.249.64.124
66.249.76.13
66.249.76.11
142.54.183.122
142.54.183.122
180.76.15.162
173.234.153.122
173.234.153.122
173.234.153.122
173.234.153.122
180.76.15.154
180.76.15.33
66.249.76.110
66.249.76.109
46.119.118.233
46.119.118.233
46.119.118.233
207.46.13.231
207.46.13.231
40.77.167.29
52.3.127.144
66.249.64.33
66.249.76.109
63.249.66.212
63.249.66.212
207.46.13.237
207.46.13.237
40.77.167.29
40.77.167.29
157.55.39.251
207.46.13.142
66.249.76.9
40.77.167.7
157.55.39.251
157.55.39.251
157.55.39.251
157.55.39.251
157.55.39.251
207.46.13.142
207.46.13.142
198.204.240.219
198.204.240.219
68.180.231.40
68.180.231.40
66.249.64.124
139.167.180.171
139.167.180.171
52.3.127.144
217.69.133.169
66.249.76.13
131.161.8.209
223.16.201.219
223.16.201.219
68.180.231.40
162.210.196.97
162.210.196.97
106.75.74.148
106.75.74.148
106.75.74.148
137.226.158.12
137.226.158.12
106.75.74.148
106.75.74.148
123.125.71.53
178.255.215.84
178.255.215.84
66.249.76.9
63.249.66.212
63.249.66.212
63.249.66.212
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
198.204.227.58
142.54.183.122
142.54.183.122
66.249.76.109
151.80.31.167
51.255.65.21
202.46.58.80
84.185.64.239
84.185.64.239
178.255.215.84
178.255.215.84
52.3.127.144
180.76.15.21
66.249.64.20
66.249.76.127
80.112.180.113
66.249.76.109
180.76.15.6
223.16.201.219
223.16.201.219
84.121.51.229
84.121.51.229
123.125.71.79
157.55.39.251
217.69.133.253
217.69.133.252
92.204.106.99
188.251.22.226
80.183.10.116
68.180.228.62
68.180.228.62
173.208.211.250
173.208.211.250
66.249.65.158
180.76.15.6
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
88.198.117.52
68.180.228.62
180.76.15.6
173.208.211.250
173.208.211.250
5.248.253.78
5.248.253.78
5.248.253.78
123.125.71.95
92.204.106.99
93.95.103.45
52.3.127.144
52.3.127.144
68.180.228.62
163.172.66.14
190.200.185.85
190.200.185.85
157.55.39.251
157.55.39.113
180.76.15.137
180.76.15.25
92.204.106.99
66.249.73.136
46.229.167.149
46.229.167.149
46.229.167.149
92.229.161.46
92.204.106.99
92.204.106.99
92.204.106.99
66.249.65.158
66.249.65.154
207.46.13.141
207.46.13.141
207.46.13.141
173.208.211.250
173.208.211.250
66.249.73.131
66.249.73.131
163.172.14.55
178.255.215.84
91.64.61.78
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
46.246.39.81
87.78.248.247
87.78.248.247
69.64.40.177
223.16.201.219
223.16.201.219
63.249.66.212
63.249.66.212
178.137.95.202
178.137.95.202
178.137.95.202
92.204.106.99
And it prints out thousands of results. I need them single, and, in best case, showing number how many duplicates of one result was there, for example: ip adress - 20 times. I thought HashMap() would help but it doesn't. Any ideas?
Kotlin has some great functions for this: groupingBy and eachCount that do exactly what you want:
import java.io.File
fun main() {
File("src/60.ips.txt")
.readLines()
.groupingBy { it }
.eachCount()
.forEach { (ip, count) -> println("$ip -> $count times") }
}
Partial output:
66.249.64.33 -> 2 times
66.249.64.124 -> 2 times
66.249.76.13 -> 2 times
66.249.76.11 -> 1 times
142.54.183.122 -> 4 times
To find the most frequent duplicate you can use maxByOrNull:
File("src/60.ips.txt")
.readLines()
.groupingBy { it }
.eachCount()
.maxByOrNull { it.value }
?.let { (ip, count) -> println("IP $ip appeared the most: $count times") }
Output:
IP 46.246.39.81 appeared the most: 17 times

Extract value from key value pairs and convert to CSV

I have below data set,
data:[{'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'}
{'name': 'samsung', 'status': 'none'}], location:[{'place': 'chennai', 'distance': '100km'},
{'place': 'bangalore', 'distance': '200km'}]
Am trying to extract the values and convert it into CSV. Am facing issues while converting as its multidimensional array. Any suggestion would be helpful.
If my data is just {'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'}, am able to get it through awk using below,
awk -F " = " -v OFS="," '
BEGIN { print "name","status","mode","place","distance" }
function printline() {
print data["name"], data["status"], data["mode"]
}
{data[$1] = $2}
NF == 0 {printline(); delete data}
END {printline()}
'
But am unable to get it with my original data set,
Original data,
data:[{'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'}
{'name': 'samsung', 'status': 'none'}], location:[{'place': 'chennai', 'distance': '100km'},
{'place': 'bangalore', 'distance': '200km'}]
Expected result,
name status mode place distance
cable none null chennai 100km
laptop loaded high bangalore 200km
samsung none null null null
Here's a start with a step-by-step approach using any awk in any shell on all UNIX boxes:
$ cat tst.awk
{ rec = (NR>1 ? rec " " : "") $0 }
END {
# Identify from rec:
# 1) [{'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'} {'name': 'samsung', 'status': 'none'}]
# 2) [{'place': 'chennai', 'distance': '100km'}, {'place': 'bangalore', 'distance': '200km'}]
str = rec
while ( match(str,/\[[^]]+/) ) {
val = substr(str,RSTART+1,RLENGTH-1)
level1vals[++numLevel1vals] = val
str = substr(str,RSTART+RLENGTH)
}
for (level1valNr=1; level1valNr<=numLevel1vals; level1valNr++) {
level1val = level1vals[level1valNr]
# Identify from level1vals[1]:
# 1) 'name': 'cable', 'status': 'none'
# 2) 'name': 'laptop', 'status': 'loaded', 'mode': 'high'
# 3) 'name': 'samsung', 'status': 'none'
# and from level1vals[2]:
# 4) 'place': 'chennai', 'distance': '100km'
# 5) 'place': 'bangalore', 'distance': '200km'
level2valNr = 0
str = level1val
while ( match(str,/{[^}]+/) ) {
val = substr(str,RSTART+1,RLENGTH-1)
++level2valNr
level2vals[level2valNr] = level2vals[level2valNr] " " val
numLevel2vals = (level2valNr > numLevel2vals ? level2valNr : numLevel2vals)
str = substr(str,RSTART+RLENGTH)
}
}
# NOTE: delete these print loops when done testing/debugging
for (level1valNr=1; level1valNr<=numLevel1vals; level1valNr++) {
print "level1vals[" level1valNr "] = <" level1vals[level1valNr] ">"
}
print ""
for (level2valNr=1; level2valNr<=numLevel2vals; level2valNr++) {
print "level2vals[" level2valNr "] = <" level2vals[level2valNr] ">"
}
}
.
$ awk -f tst.awk file
level1vals[1] = <{'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'} {'name': 'samsung', 'status': 'none'}>
level1vals[2] = <{'place': 'chennai', 'distance': '100km'}, {'place': 'bangalore', 'distance': '200km'}>
level2vals[1] = < 'name': 'cable', 'status': 'none' 'place': 'chennai', 'distance': '100km'>
level2vals[2] = < 'name': 'laptop', 'status': 'loaded', 'mode': 'high' 'place': 'bangalore', 'distance': '200km'>
level2vals[3] = < 'name': 'samsung', 'status': 'none'>
Add another round of looping using match($0,/\047[^\047]+/) to identify each 'foo' string, store in an array and then loop through that final array in the appropriate order to print the CSV.
Here is a bash/perl script to transform the original data to the "expected result" format. To make it produce result in CSV format, just change $DLMTR="\t" to $DLMTR=",":
% cat data.txt
data:[{'name': 'cable', 'status': 'none'}, {'name': 'laptop', 'status': 'loaded', 'mode': 'high'}
{'name': 'samsung', 'status': 'none'}], location:[{'place': 'chennai', 'distance': '100km'},
{'place': 'bangalore', 'distance': '200km'}]
% cat transform_data.sh
#!/usr/bin/bash
cat $* | tr "," "\n" | perl -lne '
BEGIN {
$i=$j=$data=$location=0;
# Change $DLMTR (delimiter) from "\t" (Tab) to "," for CSV format
$DLMTR="\t"
}
if (/data:/) {$data=1};
if (/location:/) {$location = 1; $data = 0;};
if ($data) { # process elements within data:[]
# \047 = single-quote and change to \042 if double-quote is required
$i++ if /\{/;
/\047name\047:/ && do { $name[$i]=$status[$i]=$mode[$i]=$place[$i]=$distance[$i]="null";
($name[$i])=/:\s*\047(.+?)\047/};
/\047status\047:/ && do {($status[$i])=/:\s*\047(.+?)\047/};
/\047mode\047:/ && do {($mode[$i])=/:\s*\047(.+?)\047/};
}
elsif ($location) { # process elements within location:[]
$j++ if /\{/;
/\047place\047:/ && do {($place[$j])=/:\s*\047(.+?)\047/};
/\047distance\047:/ && do {($distance[$j])=/:\s*\047(.+?)\047/;};
}
END {
print "name${DLMTR}status${DLMTR}mode${DLMTR}place${DLMTR}distance";
foreach $n (1..$i) {
print "$name[$n]${DLMTR}$status[$n]${DLMTR}$mode[$n]${DLMTR}$place[$n]${DLMTR}$distance[$n]";
}}'
% transform_data.sh data.txt
name status mode place distance
cable none null chennai 100km
laptop loaded high bangalore 200km
samsung none null null null

grouping tokens with same first element value

given a nested list:
(layer 0
(dielectric FR4)
(thickness 0.005)
)
(layer 1
(dielectric copper)
(thickness 0.01)
)
(layer 2
(dielectric FR4)
(thickness 0.005)
)
(physicalLayerGroup "TOP"
(minLineWidth ALWAYS_CHECK)
(maxLineWidth ALWAYS_CHECK)
(maxBondingWireLength NEVER_CHECK)
(minBondingWireLength NEVER_CHECK)
)
(physicalLayerGroup "L02"
(minLineWidth ALWAYS_CHECK)
(maxLineWidth ALWAYS_CHECK)
(maxBondingWireLength NEVER_CHECK)
(minBondingWireLength NEVER_CHECK)
)
(physicalLayerGroup "L03"
(minLineWidth ALWAYS_CHECK)
(maxLineWidth ALWAYS_CHECK)
(maxBondingWireLength NEVER_CHECK)
(minBondingWireLength NEVER_CHECK)
)
ie a list of lists where the first element of each token is identical, how can I group them? Sounds like addCondition() would fit the bill but how would one code it? Something like the following:
pp.OneOrMore( pp.Word.setName('keyy'), pp.Word.setName('valu'), pp.OneOrMore( pp.ParseResults() ).setParseAction( foo).addCondition( keyy is constant)
Any ideas?
code_warrior
The easiest approach, assuming that you know the names of each group, is to match for each group in turn by the expected names. Using a helper function (which I define below as outer_group) makes this easier:
text = """
(layer 0
(dielectric FR4)
(thickness 0.005)
)
... etc. ...
)"""
import pyparsing as pp
LPAR, RPAR = map(pp.Suppress, "()")
key_expr = pp.Word(pp.alphas)
qs = pp.quotedString().addParseAction(pp.removeQuotes)
val_expr = pp.pyparsing_common.number | qs | pp.Word(pp.printables, excludeChars='()')
# Dict keys need to be converted to str's
subgroup_key = val_expr().addParseAction(lambda t: str(t[0]))
subgroup = pp.Dict(pp.OneOrMore(pp.Group(LPAR + key_expr + val_expr + RPAR)))
# use this method to define each group by name
def outer_group(group_name):
lookahead = pp.FollowedBy(LPAR + pp.Suppress(group_name))
return lookahead + pp.Dict(pp.ZeroOrMore(pp.Group(LPAR
+ pp.Suppress(group_name)
+ subgroup_key
+ subgroup
+ RPAR)))(group_name)
# define groups by name as given in the posted question
# '&' operator generates an Each expression, which allows the groups to be
# parsed in any order
parser = outer_group('layer') & outer_group('physicalLayerGroup')
# how it works
data = parser.parseString(text)
print(data.dump())
print(data.layer['0'].dielectric)
print(data.physicalLayerGroup.TOP.maxLineWidth)
prints:
[[['0', ['dielectric', 'FR4'], ['thickness', 0.005]], ['1', ['dielectric', 'copper'], ['thickness', 0.01]], ['2', ['dielectric', 'FR4'], ['thickness', 0.005]]], [['TOP', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']], ['L02', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']], ['L03', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']]]]
- layer: [['0', ['dielectric', 'FR4'], ['thickness', 0.005]], ['1', ['dielectric', 'copper'], ['thickness', 0.01]], ['2', ['dielectric', 'FR4'], ['thickness', 0.005]]]
- 0: [['dielectric', 'FR4'], ['thickness', 0.005]]
- dielectric: 'FR4'
- thickness: 0.005
- 1: [['dielectric', 'copper'], ['thickness', 0.01]]
- dielectric: 'copper'
- thickness: 0.01
- 2: [['dielectric', 'FR4'], ['thickness', 0.005]]
- dielectric: 'FR4'
- thickness: 0.005
- physicalLayerGroup: [['TOP', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']], ['L02', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']], ['L03', ['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']]]
- L02: [['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']]
- maxBondingWireLength: 'NEVER_CHECK'
- maxLineWidth: 'ALWAYS_CHECK'
- minBondingWireLength: 'NEVER_CHECK'
- minLineWidth: 'ALWAYS_CHECK'
- L03: [['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']]
- maxBondingWireLength: 'NEVER_CHECK'
- maxLineWidth: 'ALWAYS_CHECK'
- minBondingWireLength: 'NEVER_CHECK'
- minLineWidth: 'ALWAYS_CHECK'
- TOP: [['minLineWidth', 'ALWAYS_CHECK'], ['maxLineWidth', 'ALWAYS_CHECK'], ['maxBondingWireLength', 'NEVER_CHECK'], ['minBondingWireLength', 'NEVER_CHECK']]
- maxBondingWireLength: 'NEVER_CHECK'
- maxLineWidth: 'ALWAYS_CHECK'
- minBondingWireLength: 'NEVER_CHECK'
- minLineWidth: 'ALWAYS_CHECK'
FR4
ALWAYS_CHECK
Convert parsed structure to JSON by calling asDict()
# emit JSON from parsed results
import json
print(json.dumps(data.asDict(), indent=' '))
prints:
{
"physicalLayerGroup": {
"TOP": {
"minBondingWireLength": "NEVER_CHECK",
"minLineWidth": "ALWAYS_CHECK",
"maxBondingWireLength": "NEVER_CHECK",
"maxLineWidth": "ALWAYS_CHECK"
},
"L02": {
"minBondingWireLength": "NEVER_CHECK",
"minLineWidth": "ALWAYS_CHECK",
"maxBondingWireLength": "NEVER_CHECK",
"maxLineWidth": "ALWAYS_CHECK"
},
"L03": {
"minBondingWireLength": "NEVER_CHECK",
"minLineWidth": "ALWAYS_CHECK",
"maxBondingWireLength": "NEVER_CHECK",
"maxLineWidth": "ALWAYS_CHECK"
}
},
"layer": {
"0": {
"dielectric": "FR4",
"thickness": 0.005
},
"1": {
"dielectric": "copper",
"thickness": 0.01
},
"2": {
"dielectric": "FR4",
"thickness": 0.005
}
}
}

How to execute a PL/SQL table statements

Dear friends i have these statements stored in a table and i need to execute them to receive the result.
DECODE (to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char(NRO_VIA) ||''|| to_char(NRO_PUERTA),'', 'No Disponible', to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char(NRO_VIA) ||' '|| to_char(NRO_PUERTA))',DECODE (to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||''|| to_char(NRO_VIA) ||''|| to_char(NRO_PUERTA),'', 'No Disponible', to_char((SELECT s1.streettypename FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char((SELECT s0.streetname FROM autodesk.smstreets s0, autodesk.smstreettypes s1 where s0.streettypeid = s1.streettypeid(+) AND s0.streetantiq=0 AND s0.streetid=COD_VIA)) ||' '|| to_char(NRO_VIA) ||' '|| to_char(NRO_PUERTA)) FROM cliente WHERE NRO_CLIENTE='104631'
DECODE (observaciones, NULL, 'No Disponible', '', 'No Disponible', observaciones)',DECODE (observaciones, NULL, 'No Disponible', '', 'No Disponible', observaciones) FROM cliente WHERE NRO_CLIENTE='104631'
to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_DISTRITO))',to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_DISTRITO)) FROM cliente WHERE NRO_CLIENTE='104631'
to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_PROVINCIA))',to_char((SELECT areaname FROM autodesk.amareas a0 WHERE a0.areaid=COD_PROVINCIA)) FROM cliente WHERE NRO_CLIENTE='104631'
to_char(correlativo)',to_char(correlativo) FROM cliente WHERE NRO_CLIENTE='104631'
sed',sed FROM cliente WHERE NRO_CLIENTE='104631'
to_char(telefono)',to_char(telefono) FROM s_v_cliente WHERE NRO_CLIENTE='104631'
to_char(numero_medidor)',to_char(numero_medidor) FROM tps.s_v_medid, cliente c WHERE NRO_CLIENTE='104631'
to_char(d.Consumo)',to_char(d.Consumo) FROM cliente c,(SELECT Id_Cuenta, Consumo FROM (SELECT a.Id_Cuenta, b.ENERGIA_FP Consumo FROM s_NUC_SERVICIO a, s_his_consumo b WHERE UPPER(a.tipo_Servicio) = 'ELECTRICO' AND a.id_servicio=b.id_servicio AND a.Id_Cuenta= %ID_ELEMENTO% ORDER BY fecha_lectura DESC) WHERE ROWNUM <=1) d WHERE NRO_CLIENTE='104631'
to_char(d.Potencia)',to_char(d.Potencia) FROM cliente c,(SELECT Id_Cuenta, Potencia FROM (SELECT a.Id_Cuenta, (SELECT potencia_cont_fp FROM s_v_cliente WHERE numero_cliente = a.Id_Cuenta) Potencia FROM s_NUC_SERVICIO a, s_his_consumo b WHERE UPPER(a.tipo_Servicio) = 'ELECTRICO' AND a.id_servicio = b.id_servicio AND a.Id_Cuenta = %ID_ELEMENTO% ORDER BY fecha_lectura DESC) WHERE ROWNUM <=1) d WHERE NRO_CLIENTE='104631'
fase',fase FROM cliente WHERE NRO_CLIENTE='104631'
to_char(NRO_CLIENTE)',to_char(NRO_CLIENTE) FROM cliente WHERE NRO_CLIENTE='104631'
nombre',nombre FROM cliente WHERE NRO_CLIENTE='104631'
to_char(pcr)',to_char(pcr) FROM cliente WHERE NRO_CLIENTE='104631'
TO_CHAR(DECODE(TIPO,1,'NORMAL',2,'MAXIMETRO',4,'PIMT',7,'HH.UU. Y PP.JJ',8,'ALUMBRADO PUBLICO','No Disponible'))',TO_CHAR(DECODE(TIPO,1,'NORMAL',2,'MAXIMETRO',4,'PIMT',7,'HH.UU. Y PP.JJ',8,'ALUMBRADO PUBLICO','No Disponible')) FROM cliente WHERE NRO_CLIENTE='104631'
TO_CHAR(DECODE(estado,0,'ACTIVO',1,'ELIMINADO',2,'RETIRADO',3,'NUEVO',4,'PROCESO DE RETIRO','No Disponible'))',TO_CHAR(DECODE(estado,0,'ACTIVO',1,'ELIMINADO',2,'RETIRADO',3,'NUEVO',4,'PROCESO DE RETIRO','No Disponible')) FROM cliente WHERE NRO_CLIENTE='104631'
cadena',cadena FROM cliente WHERE NRO_CLIENTE='104631'
to_char(sector)',to_char(sector) FROM cliente WHERE NRO_CLIENTE='104631'
to_char(zona)',to_char(zona) FROM cliente WHERE NRO_CLIENTE='104631'
If, as it appears, these are all select statements that return 1 row of 2 columns (minus the keyword select at the start, and with syntax errors in many) then you could do this:
declare
l_sql long;
l_col1 long;
l_col2 long;
begin
for r_sql in (select statement from my_table) loop
dbms_output.put_line('Statement: '||r_sql.statement);
l_sql := 'select '||r_sql.statement;
begin
execute immediate l_sql into l_col1, l_col2;
dbms_output.put_line('returned: '||l_col1||','||l_col2);
exception
when no_data_found then
-- take appropriate action
when too_many_rows then ...
-- take appropriate action
end;
end loop;
end;
But that will only work when the syntax errors in the data have been fixed - e.g.
to_char(NRO_CLIENTE)',to_char(NRO_CLIENTE) FROM cliente WHERE NRO_CLIENTE='104631'
... has a spurious ' after to_char(NRO_CLIENTE) that will cause the statement to fail when run.

Controller returns 406, HttpMediaTypeNotAcceptableException

I have this controller method
#RequestMapping(value = { "/{name:.+}" }, method = RequestMethod.DELETE)
public #ResponseBody
Response doSomething(#PathVariable("name") final String name) {
final response = new Response ();
response .setStatusCode("200");
return response ;
}
If i pass name as something#something.com, then I get this error
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
I have given this in my spring congig xml
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="jsonMessageConverter" />
</util:list>
</property>
</bean>
<bean id="jsonMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
This is the call stack
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:157) ~[spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:90) ~[spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:189) ~[spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:69) ~[spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) ~[spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:321) ~[spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:60) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1148) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:985) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doDelete(FrameworkServlet.java:860) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:653) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) [spring-webmvc-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) [tomcat7-websocket.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:439) [catalina.jar:7.0.47]
at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:178) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at com.samsung.ie.common.util.HttpStatusCodeFilter.doFilter(HttpStatusCodeFilter.java:17) [HttpStatusCodeFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.47]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.47]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) [catalina.jar:7.0.47]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.47]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [catalina.jar:7.0.47]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) [tomcat-coyote.jar:7.0.47]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) [tomcat-coyote.jar:7.0.47]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) [tomcat-coyote.jar:7.0.47]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
This is the request
DELETE /xxx/someone#someone.com
What am I doing wrong?

Resources