file()

Read(2303) 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)

If using the relative path, follow these rules:

1. The relative path is relative to the main directory if the latter exists; and the latter is the main directory configured in esProc option menu; search the path where the application is located (for instance, the application directory in IDE is [installation root directory]/esProc/bin);

2. When the main directory is absent and the current script file is already saved, take the directory containing the script file as the main directory;

3. When the main directory is absent and the current script file isn’t saved, search the path where the application is located (for instance, the application directory in IDE is [installation root directory]/esProc/bin)

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:

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("../demo/zh/txt/Suitor.txt")

As the main directory isn’t configured, search [installation directory]/esProc/demo/zh/txt/ for Suitor.txt.

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: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 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 retrieves zone tables of composite table fn from different nodes when z is an integer sequence; z cannot be a two-level 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:

Generate a cluster file:

 

A

 

1

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

Generate a cluster file on A1’s node.

2

=A1.open()

Open a cluster table.

3

=A2.memory()

Generate an in-memory cluster table.

4

=A2.close()

Close the cluster table.

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)

Write files to nodes; write 1.emp.ctx to node 192.168.126.1:8281 and 2.emp.xtx to node 192.168.31.165.

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))

Generate a multizone composite table.

5

=A4.append(A3.cursor())

Append A3’s data to A4’s multizone composite table.

Retrieve zone tables from nodes to generate a cluster file:

 

A

 

1

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

Define a sequence of nodes.

2

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

Retrieve zone tables from nodes to generate a cluster file; 1.empCp.ctx. and 2.empCp.ctx can be stored in node 192.168.126.1 and node 192.168.31.165:8281 respectively, or both can exist in either node.

3

=A2.open()

Open A2’s cluster file.

4

=A3.memory()

Generate an in-memory cluster table from A3’s cluster table.

5

=A4.dup()

Generate a local in-memory table from an in-memory cluster table.

file(fn:z,f)

Description:

Generate a new cluster homo-name files group with same distribution as 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 corresponding value in A2, that is, [2,3].