I'm using JDBC to create a directory object in the database.
i.e create or replace directory "dir" as 'c:\temp';
My question is:
I want to pass the path at runtime
Or at least specify path relative to current one. I mean : create or replace "dir" as './../tempdir'
Is there a way to do this or is specifying absolute path the only way out.
From Oracle Doc:
path_name Specify the full path name of the operating system directory
of the server where the files are located.
I think this is because there is no such thing as "current directory". (You are in database, not in command line :) )
You can post a question with your problem and you'll get help from community.
Related
I use MultipleOutputs to output data to some absolute paths, instead of a path relative to OutputPath.
Then, i get the error:
Error: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): Failed to create file [/test/convert.bak/326/201505110030/326-m-00035] for [DFSClient_attempt_1425611626220_29142_m_000035_1001_-370311306_1] on client [192.168.7.146], because this file is already being created by [DFSClient_attempt_1425611626220_29142_m_000035_1000_-53988495_1] on [192.168.7.149] at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:2320) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInternal(FSNamesystem.java:2083) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInt(FSNamesystem.java:2012) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFile(FSNamesystem.java:1963) at
https://issues.apache.org/jira/browse/MAPREDUCE-6357
Output files must in ${mapred.output.dir} 。
The design and implementation dosn't support outputing data to files out of ${mapred.output.dir}.
By looking into stack trace error, it seems that output file is already created.
If you want to write your data into multiple files, then try to generate those file name dynamically and use those files name as shown in code taken from Hadoop Definitive Guide
String basePath = String.format("%s/%s/part", parser.getStationId(), parser.getYear());
multipleOutputs.write(NullWritable.get(), value, basePath);
I hope this will help.
As it clearly suggests that the path you are trying to create,already exists. So try to do a check before creating that path whether that path exists or not.If exists, then delete that path.
FileSystem hdfs;
Path path = new Path (YourHadoopPath);
if (hdfs.exists(path)) {
hdfs.delete(path);
}
Currently I am using following function to get the temporary folder path for current user:
string tempPath = System.IO.Path.GetTempPath();
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
C:\Windows\TEMP
MSDN Documentation also says that above API returns current system's temporary folder.
Is there any other API available which gives me current user's temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
DO NOT use this:
System.Environment.GetEnvironmentVariable("TEMP")
Environment variables can be overridden, so the TEMP variable is not necessarily the directory.
The correct way is to use System.IO.Path.GetTempPath() as in the accepted answer.
I have this same requirement - we want to put logs in a specific root directory that should exist within the environment.
public static readonly string DefaultLogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
If I want to combine this with a sub-directory, I should be able to use Path.Combine( ... ).
The GetFolderPath method has an overload for special folder options which allows you to control whether the specified path be created or simply verified.
FREMOVE is failing with an error "ORA-29280: invalid directory path"
It works fine when I add the path to the UTL_FILE_DIR and restart the database.
This is regardless of having the directory as an Oracle directory with both READ and WRITE granted.
When using UTL_FILE you have one of two options:
Option 1: UTL_FILE_DIR must have the directory you want to use in the parameter. If it's not there it will not work. The downside is that anytime you need this parameter changed or added to you need to bounce the database. With this method the first parameter of UTL_FILE.FREMOVE will be passed the actual OS directory.
Option 2: you alternatively use an oracle Directory object. You would use the directory object name (not the actual OS directory) in the first parameter of UTL_FILE.FREMOVE
References:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm
http://www.sc.ehu.es/siwebso/KZCC/Oracle_10g_Documentacion/server.101/b10755/initparams223.htm
What is the syntax you're using for FREMOVE parameter location? For a directory, you pass in the name of the Oracle Directory object, case significant.
Currently I am using following function to get the temporary folder path for current user:
string tempPath = System.IO.Path.GetTempPath();
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
C:\Windows\TEMP
MSDN Documentation also says that above API returns current system's temporary folder.
Is there any other API available which gives me current user's temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
DO NOT use this:
System.Environment.GetEnvironmentVariable("TEMP")
Environment variables can be overridden, so the TEMP variable is not necessarily the directory.
The correct way is to use System.IO.Path.GetTempPath() as in the accepted answer.
I have this same requirement - we want to put logs in a specific root directory that should exist within the environment.
public static readonly string DefaultLogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
If I want to combine this with a sub-directory, I should be able to use Path.Combine( ... ).
The GetFolderPath method has an overload for special folder options which allows you to control whether the specified path be created or simply verified.
I have two questions.
(1) how to make move text file from folder:
C:\Data\inbox\test.txt
to target Folder?
C:\Data\outbox\test.txt
(2) how to make get list of directory files in Folder?
C:\Data\inbox\
Thank you...
Oracle provides a package of utilities for working with files, UTL_FILE. Since 9i this has included the FRENAME() procedure, which works like the unix mv command. We can use it to rename the file and/or its directory. Note that the Oracle os account must have read and write privileges on both directories. Also this procedure uses DIRECTORY objects, rather than explicit paths.
As for getting a list of files in a directory, there is no Oracle built-in. One solution is to use a Java Stored Procedure. Tom Kyte has an example of this. Find it here. There is another way of doing it since 11.1.0.7, which is to use an external table pre-processor file. Adrian Billington wrote a nice article on this. The executed file is platform dependent.
Have a look at UTL_FILE?
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm
Where you say:
2-) Question Two
Folder: C:\Data\inbox\
how to make get directory files list ?
Tom Kyte has a nice solution shown here
begin
UTL_FILE.FCOPY (
'EMPLOYEE' , -- THIS IS A ORACLE DIRECTORY
'EmpInfo.TXT' , --FILE NAME
'PROM_INCR' , -- THIS IS A ORACLE DIRECTORY
'EmpInfo.TXT' ); -- DESTINATION FILE
end;
try this