file()

Read(726) Label: file,

Here’s how to use file() function.

file( fn : cs )

Description:

Open a file with the specified name.

Syntax:

file( fn{:cs})

Note:

The function opens a file named fn.

Parameter:

fn

Name of the file to load. Both the absolute path and the relative path are acceptable. If using the relative path, then it is relative to the main path, which is the one configured on the option menu of esProc, and which by default is the current directory (the directory holding the script file)

cs

Character set, which supports jvm's built-in character set and which by default is the default value set by OS

Option:

@s

Search the file names on the non-absolute paths in a specified order: Class path -> Search path-> Main path. The search path is the one configured on the option menu of esProc, and the default main path is the current directory. With this option, the function returns the name of a read-only file

@t

Generate a temporary file under the directory of fn file. Without the fn file, create the temporary file through the Temporary directory, one of esProc options under the Tool menu. When the relative path is used to point to the temporary directory, it is relative to the configured main directory 

@a

Make the write action wait when sharing violation happens

@i

Import file into the memory and generate a file object; the in-memory file is read-only

Return value:

A file object

Example:

file("D:/Area.txt":"UTF-8")

Load the Area.txt file from the directory "D:\"; character set is UTF-8.

file("Area.txt")

Load the Area.txt file under the main path.

file@s("data/ Area.txt")

Search the class path first; if not found, then search throughout the list of search paths; lastly, search the main path if not found in the search paths.

file@t("data/Area.txt")

Create a temporary file under the directory data/

file@i("Area.txt")

Generate an in-memory read-only file object

file( fn:cs,h )

Description:

Return a remote file from a node.

Syntax:

file( fn:cs,h)

Note:

The function returns remote file fn from node h. As a local file, the remote one is both readable and writable.

Parameter:

fn

To-be-loaded file represented by an absolute path or a relative path that is relative to the main directory

cs

Character set, which is a JVM built-in one; use the system default when the parameter is absent

h

A node

Return value:

A file object

Example:

 

A

 

1

=file("D:/City.txt":"UTF-8",["192.168.46.1:8281"])

Return City.txt file under D:/ directory in node 192.168.46.1:8281 using character set UTF-8

2

=A1.import@t()

Read in content of A1’s file

3

=file("tmp.txt",["192.168.31.165:8281"])

Return tmp.txt file under the main directory in node 192.168.31.165:8281

4

>A3.write("hello world!")

Write string "hello world!" to A3’s file

file( fn:cs,hs )

Description:

Return a remote file from a sequence of nodes.

Syntax:

file( fn:cs,hs)

Note:

The function searches the local machine for remote file fn from a sequence of nodes hs; it searches the nodes in turn if it cannot find the targe file locally. The returned file is read-only.

Parameter:

fn

To-be-loaded file represented by an absolute path or a relative path that is relative to the main directory

cs

Character set, which is a JVM built-in one; use the system default when the parameter is absent

hs

A sequence of nodes

Return value:

A file object

Example:

 

A

 

1

=file("City.txt":"UTF-8",["192.168.46.1:8281","192.168.31.165:8281"])

Find City.txt file under the main directory in the sequence of nodes ["192.168.46.1:8281","192.168.31.165:8281"] using character set UTF-8

2

=A1.read()

Read in content of A1’s file

file( fn,f )

Description:

Generate a new cluster file that has same distribution type as an existing cluster file.

Syntax:

file(fn,f)

Note:

The function generates cluster file fn according to the distribution type of cluster file f and save the new file on the same node.

Parameter:

fn/f

A cluster file; supports only the composite table file

Return value:

A cluster file

Example:

 

A

 

1

=file("emp.ctx",["192.168.0.104:8281"])

Search for emp.ctx in node 192.168.0.104 and open it as a cluster file object

2

=file("emp_1.ctx",A1)

Generate a new cluster file emp_1.ctx having same distribution type as emp.ctx on the same node

3

=A2.create(#EID,GENDER)

 

file( fn:z )

Description:

Return a file or homo-name files group preceded by the corresponding zone table number(s).

Syntax:

file(fn:z)

Note:

The function returns a file preceded by the corresponding zone table number z or a homo-name files group where each file is preceded by the corresponding zone table number z from composite table file fn. The format of file name is z.fn. The function returns a file when parameter z is an integer, and a homo-name files group when it is an integer sequence.

Parameter:

fn

A composite table file

z

An integer or an integer sequence

Return value:

 Name of a composite table file or a homo-name files group object

Example:

 

A

 

1

=file("emp1.ctx":1)

Generate composite table file 1.emp1.ctx

2

=A1.create(#EID,NAME,SALARY;1)

 

3

=file("emp.ctx":[2,3,4])

Generate a homo-name files group that contains files 2.emp.ctx, 3.emp.ctx and 4.emp.ctx

4

=A3.create(#EID,NAME,SALARY)

 

file( fn:z,hs )

Description:

Generate a cluster file or a cluster homo-name files group on one or more nodes.

Syntax:

file(fn:z,hs)

Note:

The function generates a cluster file on node or a sequence of nodes hs. Parameter z is zone table number. The function generates a cluster homo-name files group when z is an integer sequence.

Parameter:

fn

A composite table file

z

Zone table number(s), which is an integer or an integer sequence

hs

A node or a sequence of nodes

Option:

@w  Enable a remote generation with parameter z and parameter hs have a one-one-one correspondence; and is equivalent to to(hs.len()) when parameter z is absent

Return value:

A cluster file

Example:

When parameter fn is a homo-name files group:

 

A

 

1

=["192.168.126.1:8281","192.168.31.165:8281"]

A sequence of nodes

2

=file("emCp.ctx":[2,3],A1)

Generate a cluster homo-name files group on A1’s nodes

3

=A2.open()

Open A2’s cluster homo-name files group

4

=A2.close()

Close the cluster homo-name files group

 

Write to a composite table file remotely:

 

A

 

1

=["192.168.126.1:8281","192.168.31.165:8281"]

A sequence of nodes

2

=file@w("emp.ctx":to(2),A1)

Generate a cluster homo-name files group on A1’s node

3

=create(k1,v1).record([1,10,2,20,3,30,4,40,10,100])

Return a table sequence

4

=A2.create(#k1,v1;if(k1<4,1,2))

Create a multi-zone composite table

5

=A4.append(A3.cursor())

Append A3’s data to A4’s multi-zone composite table

file( fn:z,f )

Description:

Generate a new cluster homo-name files group using the distribution style of an existing homo-name files group.

Syntax:

file(fn:z,f)

Note:

The function generates a new cluster homo-name files group fn using the distribution style of homo-name files group f. Parameter z is zone table number, and, when it is absent, the function use the zone table number(s) in f.

Parameter:

fn

A would-be cluster homo-name files group

z

Zone table number, which is an integer or an integer sequence

f

A cluster homo-name files group

Return value:

A cluster homo-name files group

Example:

 

A

 

1

=["192.168.126.1:8281","192.168.31.165:8281"]

A sequence of nodes

2

=file("emCp.ctx":[2,3],A1)

Return a homo-name files group

3

=file("embak.ctx",A2)

Generate a cluster homo-name files group having the same distribution type as A2’s; as parameter z is absent, use the corrponding value in A2, that is, [2,3]