How to use cbt to delete range of rows with a prefix key from BigTable - bigtable

Looks like I can read rows with a prefixed key with cbt like
cbt -project someproject -instance someinstance read sometable prefix=abc
But then how can I use cbt commend to delete those rows selected by the above command?

To be able to do this using only cbt, you would to parse the output of the read command and iterate through each result executing the deleterow command for the specific rows.
Alternatively, you could use one of the Bigtable’s Client Libraries which would be much faster.
Like in the Java client, you will find this same functionality in the other clients as well, like in the DropRowRangeRequest class for the C# Client Library.
EDIT: To delete a few rows using only cbt you could use something like this:
for x in `cbt -project my-project -instance my-instace read my-table prefix=abc | grep "abc"`; do
cbt -project my-project -instance my-instace deleterow my-table $x;
done

Related

Is there a way to move a file from one branch to another in ClearCase?

A user checked new files on the wrong branch. I would like to move them in the most efficient way there is a lot of them. My first thought is to remove the element from the branch and have the user recheck in the files on the proper branch. But I was hoping there was a way i could change the pointers?
/VOB/DIRECTORY/file##/main/1.00/1 to /VOB/DIRECTORY/file##/main/2.00/1
Whenever there are a lot of files to checkout and move, clearfsimport is a viable option.
Simply set a view to the destination branch, and import the files found in the source (and wrong) view.
See "How can I use ClearCase to “add to source control …” recursively?"
That will checkout, add, modify or remove files in the destination view in order to mirror the ones from the source (here the source is a ClearCase view, but it could actually be any folder, ClearCase view or not, where the files are).
That will be enough to "recheck in the files on the proper branch", but that won't remove the versions from the wrong branch though, and I would advice against using cleartool rmver (even though I used that here).
Perhaps a subtractive merge is better.
If you know where they are, and where you want them, you could:
1) Merge the directory and files over.
2) Use cleartool ln in a view in the destination branch to link in the files, and then merge the files individually.
If you use clearfsimport, and don't purge the added-in-the-wrong-place files, you can set yourself up for down-the-road "fun" caused by "evil twins."
Personally, since you know the files and directories that got added, where, when and by whom, you could do something like this (command lines are off-the-top-of-my-head:
Get the list of files to copy/merge
cleartool find -type d -element "created_by(baduser) && created_since(25-Jul-2016) && !created_since(26-Jul-2016)" -print > dirlist.txt
cleartool find -type fl -element "created_by(baduser) && created_since(25-Jul-2016) && !created_since(26-Jul-2016)" -print > filelist.txt
Pull the directories over by merging the parent directories while CD'd/set in a view using the destination path. Not knowing the OS involved I can't say which way you would need to parse this. If you use perl, you can grab the offset of the last instance of the directory separator and use that in substr to get the parent directory path. In the windows command prompt, you can do something like this:
SET SRCDRIVE=D:
for /f "delims==" %x in (dirlist.txt) do cleartool co -nc %~px & cleartool merge -to %~px %SRCDRIVE%~px
for /f "delims==" %x in (dirlist.txt) do cleartool co -nc %~px & cleartool merge -to %~px\%~nx %SRCDRIVE%~px\%~nx
Yes, you can do all that in a single script, and do better error checking and not trying 40x to check out the same directory.
You might also be able to merge them to the 2.0 branch (using a view selecting the 2.0 branch). To identify the elements involved, you can run a 'cleartool find' command something like this:
% cd /vobs/myvob
% cleartool find -all -version 'brtype(1.0) && created_by(user_x)' -print
The 'created_since(date-time)' query might also be useful in the compound query.
Once you're convinced you have the right set of versions, you can use '-exec' in place of the '-print' to actually perform the merge. It might look something like this:
% cleartool find -all -version 'brtype(1.0) && created_by(user_x) && created_since(29-Jun)' -exec 'cleartool merge -to $CLEARCASE_PN -version $CLEARCASE_ID_STR'
If you're happy with the results, check everything in. Then you just have to decide if you need to remove the versions on the 1.0 branch (which you can do with another 'cleartool find ... -exec ...' command).

How do I automate data export in pig?

After some slicing and dicing, I end up with a relatively small data set which I want to handle off-line. I end up writing this:
store foo into 'foo' using PigStorage('\t');
copyToLocal foo foo;
rm foo;
sh cat foo/part* | sort -k... -o foo.tsv;
sh rm -rf foo;
I would like to replace these 5 lines with a macro call, but it does not
look like I can - I get Unexpected character '|' when I do.
So, can I avoid repeating these 5 lines a few times in every script?
You have to enclose the shell command with quotes.
I don't remember the syntax exactly. Something like:
sh bash "your commands"
If this doesn't work for you, I think you can put your commands in a separate shell executable and invoke it from Pig.
I cannot:
The shell commands (used with Grunt) are not supported.
not even copyToLocal appears to be allowed.

Is it possible to configure AccuRev to use WinMerge as its diff/merge tool?

I see in AccuRev's Diff/Merge Preferences tab that the diff and merge tools can be switched to a pre-defined list of third-party tools.
These are the choices I have:
Diff
AccuRev
TkDiff
Araxis
BeyondCompare V1
BeyondCompare V2
Guiffy
Merge
AccuRev
TkDiff
Araxis
Guiffy
Is it possible to add WinMerge to these lists? If so, how?
you can not only chose from the list but also insert any cmdline you need to run, so you can hook in any diff/merge tool that supports being called with parameters. e.g. I use this for diffing:
NxNMerge.exe %1% %2% /title1:"%3%" /title2:"%4%"
For a description of the parameters open the Tools->Preferences->Diff/Merge in AccuRev and click on the help button.
vessel's answer is very accurate. One thing to keep in mind though is that WinMerge is not a 3-way merge tool, and so it will not work well using AccuRev's closest common ancestor 3-way algorithm. Diff should be fine, but I would not recommend it for Merge...
As #vessel said, you can insert any commandline just into the edit field.
The command line for WinMerge is the following:
WinMergeU.exe /dl "%3%" /dr "%4%" %1% %2%
Better choice is KDiff3, which also supports 3-way merge. Both commands below:
Diff:
"c:\Program Files\KDiff3\kdiff3.exe" %1% %2%
Merge:
"c:\Program Files\KDiff3\kdiff3.exe" %1% %2% %a% -o %o%

Using command output in DOS

I would like to run a command in DOS, which uses the output of another command as its part, something that single back-quote (``) allows to do on UNIX or Linux.
For example, if myCommand returns a list of files, I would like to execute in DOS some analog of the UNIX command
grep `myCommand`
How would one do that in DOS?
Thank you in advance for your help.
You can pipe two commands:
command1 | command2
But there aren't a whole lot of commands whos input/ouput plays well with each other. You'd probably be best off using a for loop. The basic syntax is:
for /f %A in ('command1') do command2 %A
Unless you try the for %%i in ... syntax, I do not see a hope in DOS. DOS is not Unix.
Another solution is to build a new batch using the for loop (with # and echo) and start the new batch at the end.
You may need to do this recursively.

Script for Testing with Input files and Output Solutions

I have a set of *.in files and a set of *.soln files with matching files names. I would like to run my program with the *.in file as input and compare the output to the ones found in the *.soln files. What would be the best way to go about this? I can think of 3 options.
Write some driver in Java to list files in the folder, run the program, and compare. This would be hard and difficult.
Write a bash script to do this. How?
Write a python script to do this?
I would go for a the bash solution. Also given that what you are doing is a test, I would always save the output of the myprogram so that if there are failures, that you always have the output to compare it to.
#!/bin/bash
for infile in *.in; do
basename=${infile%.*}
myprogram $infile > $basename.output
diff $basename.output $basename.soln
done
Adding the checking or exit statuses etc. as required by your report.
If the program exists, I suspect the bash script is the best bet.
If your soln files are named right, some kind of loop like
for file in base*.soln
do
myprogram > new_$file
diff $file new_$file
done
Of course, you can check the exit code of diff and
do various other things to create a test report . . .
That looks simplest to me . . .
Karl
This is primarily a problem that requires the use of the file-system with minimal logic. Bash isn't a bad choice for such problems. If it turns out you want to do something more complicated than just comparing for equality Python becomes a more attractive choice. Java doesn't seem like a good choice for a throwaway script such as this.
Basic bash implementation might look something like this:
cd dir_with_files
program=your_program
input_ext=".in"
compare_to_ext=".soIn"
for file in *$from_extension; do
diff <("$program" "$i") "${file:0:$((${#file}-3))}$compare_to_ext"
done
Untested.