Example from Optaplanner documentation on cartesianProductMoveSelector throws an exception: - optaplanner

What is the proper way to do the cartesian move of two changeMoveSelectors for two planning variables?
I took the cartesianProductMoveSelector example From the documentation for Optaplanner version 8.25. The following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>com.company.MySolution</solutionClass>
<entityClass>com.company.Standstill</entityClass>
<entityClass>com.company.PlanningVisit</entityClass>
<environmentMode>REPRODUCIBLE</environmentMode>
<randomSeed>50</randomSeed>
<environmentMode>FULL_ASSERT</environmentMode>
<scoreDirectorFactory>
<constraintProviderClass>com.company.MyConstraintProvider
</constraintProviderClass>
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<termination>
<minutesSpentLimit>1800</minutesSpentLimit>
</termination>
<customPhase>
<customPhaseCommandClass>com.company.phase.MySolutionInit</customPhaseCommandClass>
</customPhase>
<constructionHeuristic>
<changeMoveSelector>
</changeMoveSelector>
<constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<termination>
<minutesSpentLimit>300</minutesSpentLimit>
</termination>
<unionMoveSelector>
<moveListFactory>
<variableName>previousStandstill</variableName>
<moveListFactoryClass>com.company.moves.RideChangeMoveFactory</moveListFactoryClass>
</moveListFactory>
<cartesianProductMoveSelector>
<changeMoveSelector>
<entitySelector id="cartesianProductEntitySelector"/>
<valueSelector>
<variableName>previousStandstill</variableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="cartesianProductEntitySelector"/>
<valueSelector>
<variableName>startModifier</variableName>
</valueSelector>
</changeMoveSelector>
</cartesianProductMoveSelector>
<swapMoveSelector>
<variableName>previousStandstill</variableName>
</swapMoveSelector>
<subChainChangeMoveSelector>
<subChainSelector>
<valueSelector variableName="previousStandstill">
</valueSelector>
</subChainSelector>
<valueSelector variableName="previousStandstill">
</valueSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainChangeMoveSelector>
<subChainSwapMoveSelector>
<subChainSelector>
<valueSelector variableName="previousStandstill">
</valueSelector>
</subChainSelector>
<secondarySubChainSelector>
<valueSelector variableName="previousStandstill">
</valueSelector>
</secondarySubChainSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainSwapMoveSelector>
<tailChainSwapMoveSelector>
<valueSelector variableName="previousStandstill">
</valueSelector>
</tailChainSwapMoveSelector>
</unionMoveSelector>
<acceptor>
<entityTabuSize>12</entityTabuSize>
</acceptor>
<forager>
<acceptedCountLimit>3000</acceptedCountLimit>
</forager>
</localSearch>
</solver>
Throws an
Multiple EntityMimicRecorders (usually EntitySelectors) have the same id (cartesianProductEntitySelector).

I believe the problem was in the build process, so the source XML configuration and the XML that was actually used were not the same. I can confirm that this configuration works:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>com.company.MySolution</solutionClass>
<entityClass>com.company.Standstill</entityClass>
<entityClass>com.company.PlanningVisit</entityClass>
<environmentMode>REPRODUCIBLE</environmentMode>
<randomSeed>50</randomSeed>
<environmentMode>FULL_ASSERT</environmentMode>
<scoreDirectorFactory>
<constraintProviderClass>com.company.MyConstraintProvider
</constraintProviderClass>
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<termination>
<minutesSpentLimit>1800</minutesSpentLimit>
</termination>
<customPhase>
<customPhaseCommandClass>com.company.phase.MySolutionInit</customPhaseCommandClass>
</customPhase>
<constructionHeuristic>
<changeMoveSelector>
</changeMoveSelector>
<constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<termination>
<minutesSpentLimit>300</minutesSpentLimit>
</termination>
<cartesianProductMoveSelector>
<changeMoveSelector>
<entitySelector id="entitySelector"/>
<valueSelector variableName="previousStandstill"/>
</changeMoveSelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="entitySelector"/>
<valueSelector variableName="startModifier">
</valueSelector>
</changeMoveSelector>
</cartesianProductMoveSelector>
<acceptor>
<entityTabuSize>12</entityTabuSize>
</acceptor>
<forager>
<acceptedCountLimit>3000</acceptedCountLimit>
</forager>
</localSearch>
</solver>
I will edit this answer, once I add back the rest of the configs and will know exactly what was wrong.

Related

How to create unique id for users during extract from oracle xml

I have xmldata in my oracle DB, there are different applicants for a particular appID in my oracle DB. Note the appID is a field in the oracle table while the applicants are in the xmldata(I have multiple applicants in this xml) I would like to create a unique id for the applicants.
In the sample data, there are 3 applicants. how do I create unique ids in my select statement.
WITH t( xml ) AS
(
SELECT XMLType('<loanApplication xmlns="http://www.abcdef.com/Schema/FCX/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<applicantGroup>
<applicantGroupTypeDd>0</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>1</assetTypeDd>
<assetValue>1500.0</assetValue>
</asset>
<asset>
<assetDescription>RayM</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>8</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 Hyundai</assetDescription>
<assetTypeDd>4</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
<applicantGroup>
<applicantGroupTypeDd>1</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>2</assetTypeDd>
<assetValue>15000.0</assetValue>
</asset>
<asset>
<assetDescription>Bay</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>9</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 car</assetDescription>
<assetTypeDd>3</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
<applicantGroup>
<applicantGroupTypeDd>3</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>100.0</assetValue>
</asset>
<asset>
<assetDescription>RayM</assetDescription>
<assetTypeDd>8</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>7</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 Hyundai</assetDescription>
<assetTypeDd>5</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
</loanApplication>')
FROM dual
)
SELECT JSON_OBJECT (
KEY 'Assets' value y.Assets
) assets
FROM t,
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/applicantGroup/applicant/asset'
PASSING xml
COLUMNS
Assets INT PATH 'assetValue') y
Results, I need
AppId
applicantId
assetTypeDd
1
1
[1,6,8,4]
1
2
[1,2,6,9,3]
1
3
[3,6,8,7,5]
Thanks
Consider XPath's ancestor axis and count pf preceding-sibling since it appears one applicant node falls under each applicantGroup:
WITH t( xml_data ) AS
(
SELECT XMLType('<loanApplication xmlns="http://www.abcdef.com/Schema/FCX/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<applicantGroup>
<applicantGroupTypeDd>0</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>1</assetTypeDd>
<assetValue>1500.0</assetValue>
</asset>
<asset>
<assetDescription>RayM</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>8</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 Hyundai</assetDescription>
<assetTypeDd>4</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
<applicantGroup>
<applicantGroupTypeDd>1</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>2</assetTypeDd>
<assetValue>15000.0</assetValue>
</asset>
<asset>
<assetDescription>Bay</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>9</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 car</assetDescription>
<assetTypeDd>3</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
<applicantGroup>
<applicantGroupTypeDd>3</applicantGroupTypeDd>
<applicant>
<asset>
<assetDescription>neweg</assetDescription>
<assetTypeDd>6</assetTypeDd>
<assetValue>100.0</assetValue>
</asset>
<asset>
<assetDescription>RayM</assetDescription>
<assetTypeDd>8</assetTypeDd>
<assetValue>60000</assetValue>
</asset>
<asset>
<assetDescription>TDC</assetDescription>
<assetTypeDd>7</assetTypeDd>
<assetValue>100</assetValue>
</asset>
<asset>
<assetDescription>2007 Hyundai</assetDescription>
<assetTypeDd>5</assetTypeDd>
<assetValue>2500</assetValue>
</asset>
</applicant>
</applicantGroup>
</loanApplication>')
FROM dual
)
SELECT y.ApplicantId AS "applicantId",
LISTAGG(y.AssetTypeDd, ',') AS "assetTypeDd",
LISTAGG(y.Assets, ',') AS "assets"
FROM t,
XMLTABLE(
XMLNAMESPACES('http://www.abcdef.com/Schema/FCX/1' AS "d",
DEFAULT 'http://www.abcdef.com/Schema/FCX/1'),
'//d:asset'
PASSING xml_data
COLUMNS
ApplicantId INT PATH 'count(ancestor::applicantGroup/preceding-sibling::*)+1',
AssetTypeDd INT PATH 'assetTypeDd',
Assets INT PATH 'assetValue'
) y
GROUP BY y.ApplicantId
ORDER BY y.ApplicantId
Online Demo

libreoffice convert docx to odt lost bookmark

I use the following command converting a docx to odt, one of the bookmarks get lost.
"libreoffice --headless --convert-to odt output.docx --outdir ./"
----- output.docx
------- following bookmarks was created by python-docx
<w:p w14:paraId="5D4F37CC" w14:textId="1FE5A142" w:rsidR="007E1B42" w:rsidRDefault="00356283" w:rsidP="00356283">
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>a</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark4"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p w14:paraId="34895FBC" w14:textId="518CEA5B" w:rsidR="007E1B42" w:rsidRDefault="00CF7EC0" w:rsidP="00CF7EC0">
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>b</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark5"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
...
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>Index1</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark34"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p>
<w:r>
<w:t>--a......................................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark4" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p>
<w:r>
<w:t>----b................................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark5" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p>
<w:r>
<w:t>--Index1.......................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark34" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p/>
---- output.odt
<text:h text:style-name="Heading_20_1" text:outline-level="1">
a
<text:bookmark text:name="xxbookmark4"/>
</text:h>
<text:h text:style-name="Heading_20_2" text:outline-level="2">
b
<text:bookmark text:name="xxbookmark5"/>
</text:h>
...
<text:h text:style-name="P1" text:outline-level="1">Index1</text:h>
# issue here: xxbookmark34 is lost.
Index1 was created using python-docx, the other two headings are just edit manually in Word.
Anybody can help, or give some hint.
I compared the xml file in docx and can not find any different between the "Index1" and other two.

Parse xml file in pandas

I have this xml file (it's called "LogReg.xml" and it contains some information about a logistic regression (I am interested in the name of the features and their coefficient - I'll explain in more detail below):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PMML xmlns="http://www.dmg.org/PMML-4_4" xmlns:data="http://jpmml.org/jpmml-model/InlineTable" version="4.4">
<Header>
<Application name="JPMML-SkLearn" version="1.6.35"/>
<Timestamp>2022-02-15T09:44:54Z</Timestamp>
</Header>
<MiningBuildTask>
<Extension name="repr">PMMLPipeline(steps=[('classifier', LogisticRegression())])</Extension>
</MiningBuildTask>
<DataDictionary>
<DataField name="Target" optype="categorical" dataType="integer">
<Value value="0"/>
<Value value="1"/>
</DataField>
<DataField name="const" optype="continuous" dataType="double"/>
<DataField name="grade" optype="continuous" dataType="double"/>
<DataField name="emp_length" optype="continuous" dataType="double"/>
<DataField name="dti" optype="continuous" dataType="double"/>
<DataField name="Orig_FicoScore" optype="continuous" dataType="double"/>
<DataField name="inq_last_6mths" optype="continuous" dataType="double"/>
<DataField name="acc_open_past_24mths" optype="continuous" dataType="double"/>
<DataField name="mort_acc" optype="continuous" dataType="double"/>
<DataField name="mths_since_recent_bc" optype="continuous" dataType="double"/>
<DataField name="num_rev_tl_bal_gt_0" optype="continuous" dataType="double"/>
<DataField name="percent_bc_gt_75" optype="continuous" dataType="double"/>
</DataDictionary>
<RegressionModel functionName="classification" algorithmName="sklearn.linear_model._logistic.LogisticRegression" normalizationMethod="logit">
<MiningSchema>
<MiningField name="Target" usageType="target"/>
<MiningField name="const"/>
<MiningField name="grade"/>
<MiningField name="emp_length"/>
<MiningField name="dti"/>
<MiningField name="Orig_FicoScore"/>
<MiningField name="inq_last_6mths"/>
<MiningField name="acc_open_past_24mths"/>
<MiningField name="mort_acc"/>
<MiningField name="mths_since_recent_bc"/>
<MiningField name="num_rev_tl_bal_gt_0"/>
<MiningField name="percent_bc_gt_75"/>
</MiningSchema>
<Output>
<OutputField name="probability(0)" optype="continuous" dataType="double" feature="probability" value="0"/>
<OutputField name="probability(1)" optype="continuous" dataType="double" feature="probability" value="1"/>
</Output>
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
<RegressionTable intercept="0.0" targetCategory="0"/>
</RegressionModel>
</PMML>
I have parsed it using this code:
from lxml import objectify
path = 'LogReg.xml'
parsed = objectify.parse(open(path))
root = parsed.getroot()
data = []
if True:
for elt in root.RegressionModel.RegressionTable:
el_data = {}
for child in elt.getchildren():
el_data[child.tag] = child.text
data.append(el_data)
perf = pd.DataFrame(data)
I am interested in parsing this bit:
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
so that I can build the following dictionary:
myDict = {
"const : 0.8013433785974717,
"grade" : 0.9010481046582982,
"emp_length" : 0.9460686056314133,
"dti" : 0.5117062988491518,
"Orig_FicoScore" : 0.07944303372859234,
"inq_last_6mths" : 0.20516234445402765,
"acc_open_past_24mths" : 0.4852503249658917,
"mort_acc" : 0.6673203078463711,
"mths_since_recent_bc" : 0.1962158305958366,
"num_rev_tl_bal_gt_0" : 0.12964661294856686,
"percent_bc_gt_75" : 0.04534570018290847
}
Basically, in the dictionary the Key is the name of the feature and the value is the coefficient of the logistic regression.
Please can anyone help me with the code?
I'm not sure you need pandas for this, but you do need to handle the namespaces in your xml.
Try something along these lines:
myDict = {}
#register the namespace
ns = {'xx': 'http://www.dmg.org/PMML-4_4'}
#you could collapse the next two into one line, but I believe it's clearer this way
rt = root.xpath('//xx:RegressionTable[.//xx:NumericPredictor]',namespaces=ns)[0]
nps = rt.xpath('./xx:NumericPredictor',namespaces=ns)
for np in nps:
myDict[np.attrib['name']]=np.attrib['coefficient']
myDict
The output should be your expected output.

How to debug redis with memory usage is over 20GB?

I am having a serious issue with Redis, and I cannot get my head around the root cause of the issue, I am running dockerised redis6-alpine and it is working well in some other setups with the exact configurations, any hint/guidance are appreciated! here is a quick view of my configurations:
# Server
redis_version:6.0.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:e0ee1c530b6d150b
redis_mode:standalone
os:Linux 4.19.0-16-amd64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:10.2.1
process_id:1
run_id:79e32727ad7a6eb2a9427060ba44fa918c01de5a
tcp_port:6379
uptime_in_seconds:215118
uptime_in_days:2
hz:10
configured_hz:10
lru_clock:14634210
executable:/data/redis-server
config_file:
io_threads_active:0
# Clients
connected_clients:58
client_recent_max_input_buffer:131072
client_recent_max_output_buffer:786456
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
# Memory
used_memory:23814128424
used_memory_human:22.18G
used_memory_rss:25484832768
used_memory_rss_human:23.73G
used_memory_peak:26912783984
used_memory_peak_human:25.06G
used_memory_peak_perc:88.49%
used_memory_overhead:43319344
used_memory_startup:803160
used_memory_dataset:23770809080
used_memory_dataset_perc:99.82%
allocator_allocated:23814697320
allocator_active:25313169408
allocator_resident:25528991744
total_system_memory:135186935808
total_system_memory_human:125.90G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.06
allocator_frag_bytes:1498472088
allocator_rss_ratio:1.01
allocator_rss_bytes:215822336
rss_overhead_ratio:1.00
rss_overhead_bytes:-44158976
mem_fragmentation_ratio:1.07
mem_fragmentation_bytes:1670633120
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:1345144
mem_aof_buffer:8
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
# Persistence
loading:0
rdb_changes_since_last_save:193999866
rdb_bgsave_in_progress:0
rdb_last_save_time:1625031828
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:167
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:565936128
module_fork_in_progress:0
module_fork_last_cow_size:0
aof_current_size:18283706329
aof_base_size:18280419536
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0
# Stats
total_connections_received:5857404
total_commands_processed:518486668
instantaneous_ops_per_sec:1821
total_net_input_bytes:177162832735
total_net_output_bytes:8187427886085
instantaneous_input_kbps:432.05
instantaneous_output_kbps:53204.55
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:30957
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:21298
evicted_keys:0
keyspace_hits:372132606
keyspace_misses:10318752
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:593467
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:4
total_reads_processed:394752846
total_writes_processed:382030652
io_threaded_reads_processed:0
io_threaded_writes_processed:0
# Replication
role:master
connected_slaves:0
master_replid:2a7e6a090bdaa0474ee666c6c6b555e0c1c3942a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:12596.074365
used_cpu_user:6090.006186
used_cpu_sys_children:164.531584
used_cpu_user_children:1229.917070
# Modules
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=134616,expires=96904,avg_ttl=777017159
db1:keys=348560,expires=332665,avg_ttl=63989490
redis appendonly.aof file size

xml file data imported to sql with script

im having this kind of xml:
<?xml version="1.0"?>
-<recordedData>
<machine>ZSK40-2</machine>
<date>2013/09/21</date>
<hour>05:32</hour>-<CollectedData>-<variable>
<Name>PRODUCT</Name>
<Value>FILLER 580</Value>
</variable>-<variable>
<Name>LOT_NUMBER</Name>
<Value>CG 00063 0</Value>
</variable>-<variable>
<Name>SHIFT_SUPERVISOR</Name>
<Value> covaliu l</Value>
</variable>-<variable>
<Name>KGH_ALL_SET</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_ALL_REAL</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_F1_SET</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KGH_F1_REAL</Name>
<Value>0</Value>
</variable>-<variable>
<Name>K_F1</Name>
<Value>43</Value>
</variable>-<variable>
<Name>SCREW_RPM_SET</Name>
<Value>550</Value>
</variable>-<variable>
<Name>SCREW_RPM_REAL</Name>
<Value>550.085388183594</Value>
</variable>-<variable>
<Name>TORQUE</Name>
<Value>1.21340000629425</Value>
</variable>-<variable>
<Name>CURRENT</Name>
<Value>60.1959991455078</Value>
</variable>-<variable>
<Name>KW_KG</Name>
<Value>0</Value>
</variable>-<variable>
<Name>KW</Name>
<Value>-0.990000009536743</Value>
</variable>-<variable>
<Name>MELT_PRESSURE</Name>
<Value>0</Value>
</variable>-<variable>
<Name>MELT_TEMPERATURE</Name>
<Value>214</Value>
</variable>-<variable>
<Name>PV1</Name>
<Value>216</Value>
</variable>-<variable>
<Name>SP1</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV2</Name>
<Value>239</Value>
</variable>-<variable>
<Name>SP2</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV3</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP3</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV4</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP4</Name>
<Value>220</Value>
</variable>-<variable>
<Name>PV5</Name>
<Value>209</Value>
</variable>-<variable>
<Name>SP5</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV6</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP6</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV7</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP7</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV8</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP8</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV9</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP9</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV10</Name>
<Value>210</Value>
</variable>-<variable>
<Name>SP10</Name>
<Value>210</Value>
</variable>-<variable>
<Name>PV11</Name>
<Value>220</Value>
</variable>-<variable>
<Name>SP11</Name>
<Value>220</Value>
</variable>
</CollectedData>
</recordedData>
Can anyone provide a sample sql script for extracting all the data from it please.
i would really apreciate this since im new to xml.
Thanks in advance.
If you have your data in a table already, you can use something like this:
DECLARE #Tmp TABLE (ID INT NOT NULL, XmlContent XML)
INSERT INTO #TMP VALUES(1, '......(your entire XML here).......)
SELECT
ID,
MACHINE = XmlContent.value('(/recordedData/machine)[1]', 'varchar(50)'),
RecordingDate = XmlContent.value('(/recordedData/date)[1]', 'varchar(50)'),
RecordingTime = XmlContent.value('(/recordedData/hour)[1]', 'varchar(50)'),
VariableName = XVar.value('(Name)[1]', 'varchar(50)'),
VariableValue = XVar.value('(Value)[1]', 'varchar(50)')
FROM
#Tmp
CROSS APPLY
XmlContent.nodes('/recordedData/CollectedData/variable') AS XTbl(XVar)
This gives you an output something like:
.... and so on - listing all the variables with their name and value.