When running BCP from my Java application it exits with status code 0 when 1 is expected.
I run bcp with an invalid combination of data and formatting file and bcp gives the following error:
Starting copy...
SQLState = 22005, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid character value for cast specification
BCP copy in failed
BCP however exits with exit code 0 and not 1, as i suspect. Now it is extremely difficult to see if something failed while running BCP. Exitting with the right code works once they match to some degree (like same delimiters).
Command
PS C:\Users\feh\Desktop> bcp integrate_test.dbo.AS_LOADER_DELIMITED in .\data.dat -S "10.0.0.161\SQL2K5,1048" -U user -P pass -f .\formatting.ctl -m 1
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOF encountered in BCP data-file
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1
PS C:\Users\feh\Desktop> $lastexitcode
0
How can i validate a formatting file to the data and get a exit code 1 when they do not match?
If the bcp is "in" the consider using BULK INSERT. This does the same as bcp but can be trapped using SQL Server TRY/CATCH or normal exception handling
Otherwise, are you trapping %ERRORLEVEL% and not some other code?
Related
I want to extract the code count for the below command output. In the below example expected output is 286. What will be the regular expression to extract the code count?
Want to parse the below string in windows:
1 text file.
1 unique file.
0 files ignored.
http://cloc.sourceforge.net v 1.64 T=0.01 s (86.1 files/s, 1119.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ 1 0 0 13
-------------------------------------------------------------------------------
You can grep the last digits of a line by
grep -P "\d+$"
I can parse it in Linux using below:
grep -Eo '[0-9]+$'
I had written some wrong syntax for an SQL query. But still, it outputted no error with a java tomcat server. Running on Debian 9.
MySQL Version:
mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64)
The query was as follows, I had misplaced the comma ',' with 'and' after the set operator
UPDATE table_pod_print set print_status = 1 and operator_id = 2091 where id = 1
I tried running it on the console, which gave me the following output:
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Please help me in understanding why the query worked in the first place.
In MySQL SELECT 1 AND 0; produces 0 because the AND operator evaluates operands as a logical AND. Looking at your query the SET print_status was evaluated as (adding additional brackets for clarity):
print_status = (1 AND (operator_id = 2091))
which mean it would be 1 AND 1 if operator_id = 2091 for updated id = 1 row was true and 1 AND 0 if not.
Using the code:
all_reviews = db_handle.find().sort('reviewDate', pymongo.ASCENDING)
print all_reviews.count()
print all_reviews[0]
print all_reviews[2000000]
The count prints 2043484, and it prints all_reviews[0].
However when printing all_reviews[2000000], I get the error:
pymongo.errors.OperationFailure: database error: Runner error: Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 33554432 bytes
How do I handle this?
You're running into the 32MB limit on an in-memory sort:
https://docs.mongodb.com/manual/reference/limits/#Sort-Operations
Add an index to the sort field. That allows MongoDB to stream documents to you in sorted order, rather than attempting to load them all into memory on the server and sort them in memory before sending them to the client.
As said by kumar_harsh in the comments section, i would like to add another point.
You can view the current buffer usage using the below command over the admin database:
> use admin
switched to db admin
> db.runCommand( { getParameter : 1, "internalQueryExecMaxBlockingSortBytes" : 1 } )
{ "internalQueryExecMaxBlockingSortBytes" : 33554432, "ok" : 1 }
It has a default value of 32 MB(33554432 bytes).In this case you're running short of buffer data so you can increase buffer limit with your own defined optimal value, example 50 MB as below:
> db.adminCommand({setParameter: 1, internalQueryExecMaxBlockingSortBytes:50151432})
{ "was" : 33554432, "ok" : 1 }
We can also set this limit permanently by the below parameter in the mongodb config file:
setParameter=internalQueryExecMaxBlockingSortBytes=309715200
Hope this helps !!!
Note:This commands supports only after version 3.0 +
solved with indexing
db_handle.ensure_index([("reviewDate", pymongo.ASCENDING)])
If you want to avoid creating an index (e.g. you just want a quick-and-dirty check to explore the data), you can use aggregation with disk usage:
all_reviews = db_handle.aggregate([{$sort: {'reviewDate': 1}}], {allowDiskUse: true})
(Not sure how to do this in pymongo, though).
JavaScript API syntax for the index:
db_handle.ensureIndex({executedDate: 1})
In my case, it was necessary to fix nessary indexes in code and recreate them:
rake db:mongoid:create_indexes RAILS_ENV=production
As the memory overflow does not occur when there is a needed index of field.
PS Before this I had to disable the errors when creating long indexes:
# mongo
MongoDB shell version: 2.6.12
connecting to: test
> db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )
Also may be needed reIndex:
# mongo
MongoDB shell version: 2.6.12
connecting to: test
> use your_db
switched to db your_db
> db.getCollectionNames().forEach( function(collection){ db[collection].reIndex() } )
I have a collection called User(with userId as primary key) and am trying to export certain documents based on the Query attribute supported by MonogExport.
My MongoExport command looks like :
mongoexport -h localhost -d mydb -o C:\account\user.json --collection user--query '{userId: {$in :[1233,1234,1235,1236]}}'
Based on the above, mongo creates a json file for us. But my major concern is, how to process this command, if length of this command increases to more than 8192 chracters(Message Displayed : the process command is too long)
This is not the problem of mongo. Windows command line only takes 8191 characters per line.
Refer here for the solution
I am trying to get data from elasticsearch using Java's GET API. but I keep on getting the IndexMisingException.
Exception in thread "main" org.elasticsearch.indices.IndexMissingException: [logstash-*] missing
at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:768)
at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:691)
at org.elasticsearch.cluster.metadata.MetaData.concreteSingleIndex(MetaData.java:748)
at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.<init>(TransportShardSingleOperationAction.java:139)
at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.<init>(TransportShardSingleOperationAction.java:116)
at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:89)
at org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:55)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:75)
at org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:98)
at org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:193)
at org.elasticsearch.action.get.GetRequestBuilder.doExecute(GetRequestBuilder.java:201)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at elasticConnection.ClientElastic.main(ClientElastic.java:18)
I have the Index in elasticsearch.
health status **index** pri rep docs.count docs.deleted store.size pri.store.size
yellow open **events** 5 1 39 0 48.7kb 48.7kb
yellow open **logstash-2016.03.30** 5 1 152 0 137.8kb 137.8kb
please help.
Your indexes are still waiting for replica, which generally we avoid when working on a single node.
Run this command on your local host :
curl -XPUT 'localhost:9200/_settings' -d '{ "index" : { "number_of_replicas" : 0 } }'
This should change the index status to green and your program should be good to go.